简体   繁体   中英

Code Igniter SEO friendly URL rewriting

I'm facing issues while rewriting URLs in codeigniter framework.

Here is my URL

http://localhost/article/lg-watch-urbane-vs-moto-360-a-detailed-real-world-comparison/19

And I've a controller like this :

class Article extends CI_Controller {

function __construct()
{
    $this->set_page_name( "View Article" );
}

function index($perma_link="",$id="")
{
    $this->response['article'] = $this->restutil->get("portal/articles/get/".$id,array('id'=>$id))->article;

    $this->render_view('articles/view');
}
}

And my .htaccess is like this:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    # Removes index.php from ExpressionEngine URLs
    RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
    RewriteCond %{REQUEST_URI} !/system/.* [NC]
    RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]

    # Directs all EE web requests through the site index file
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteRule ^(.*)$ /index.php/$1 [L]

    RewriteRule ^article/([\w-]+)$ /index.php/article/index/$1 [L]

</IfModule>

I want redirect, all the request which comes as "article" to "article/index" function. But it is not happening currently. Only if i give "index" in the URL ie; http://localhost/article/index/lg-watch-urbane-vs-moto-360-a-detailed-real-world-comparison/19

Then only the page is loading. Otherwise it is not. Can anybody help me fix this?

You'll be able to do this, with CI routes.

$route['article/(:any)/(:num)'] = 'article/index/$1/$2;

This should work. Re-routes anything that comes into article, to the index method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM