Rads
Rads

Reputation: 195

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?

Upvotes: 0

Views: 1482

Answers (1)

Craig
Craig

Reputation: 1823

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.

Upvotes: 1

Related Questions