Code Igniter SEO友好的URL重写

时间:2015-05-18 13:46:07

标签: php .htaccess codeigniter url-rewriting seo

我在codeigniter框架中重写网址时遇到问题。

这是我的网址

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

我是这样的控制器:

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');
}
}

我的.htaccess是这样的:

<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>

我想要重定向,所有请求来自&#34;文章&#34;到&#34;文章/索引&#34;功能。但目前还没有发生。只有我给&#34;索引&#34;在URL中;     http://localhost/article/index/lg-watch-urbane-vs-moto-360-a-detailed-real-world-comparison/19

然后只加载页面。否则就不是。任何人都可以帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:1)

您可以使用CI路线执行此操作。

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

这应该有效。将文章中的任何内容重新路由到索引方法。

相关问题