【发布时间】:2015-07-30 01:25:05
【问题描述】:
我在 codeigniter 框架中重写 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/*(.*) /$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>
我想要重定向,所有以“文章”形式出现的请求到“文章/索引”功能。但目前还没有发生。仅当我在 URL 中给出“索引”时,即; http://localhost/article/index/lg-watch-urbane-vs-moto-360-a-detailed-real-world-comparison/19
然后只有页面正在加载。否则不是。谁能帮我解决这个问题?
【问题讨论】:
-
这是我找到的不同 htaccess 文件的链接,您可以尝试github.com/riwakawebsitedesigns/htaccess_for_codeigniter。正如@Craig 指出的,确保你设置了你的路线codeigniter.com/userguide2/general/routing.html
标签: php .htaccess codeigniter url-rewriting seo