Codeigniter SEO 友好 URL 重写
Code Igniter SEO friendly URL rewriting
我在 codeigniter 框架中重写 URL 时遇到问题。
这是我的 URL
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/*(.*) / [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/ [L]
RewriteRule ^article/([\w-]+)$ /index.php/article/index/ [L]
</IfModule>
我想要重定向,所有来自 "article" 的请求到 "article/index" 函数。但目前还没有发生。仅当我在 URL 中给出 "index" 即;
http://localhost/article/index/lg-watch-urbane-vs-moto-360-a-detailed-real-world-comparison/19
然后只有页面正在加载。否则它不是。谁能帮我解决这个问题?
您将能够通过 CI 条路线做到这一点。
$route['article/(:any)/(:num)'] = 'article/index//;
这应该有效。将进入文章的任何内容重新路由到索引方法。
我在 codeigniter 框架中重写 URL 时遇到问题。
这是我的 URL
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/*(.*) / [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/ [L]
RewriteRule ^article/([\w-]+)$ /index.php/article/index/ [L]
</IfModule>
我想要重定向,所有来自 "article" 的请求到 "article/index" 函数。但目前还没有发生。仅当我在 URL 中给出 "index" 即; http://localhost/article/index/lg-watch-urbane-vs-moto-360-a-detailed-real-world-comparison/19
然后只有页面正在加载。否则它不是。谁能帮我解决这个问题?
您将能够通过 CI 条路线做到这一点。
$route['article/(:any)/(:num)'] = 'article/index//;
这应该有效。将进入文章的任何内容重新路由到索引方法。