我正在使用 CI 构建一个类似博客的网站。我正在使用HMVC 插件。我正在使用的模块是“/journal”。
个别文章可在 /journal/article/ID/SLUG 访问。这很好用,但我想使用 mod_rewrite 将 URI 缩短为 /journal/ID/SLUG。
这是我的规则:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^journal/([0-9]+)(.*)$ index.php?/journal/article/$1$2 [L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1
为了测试,我使用 /journal/2。
我知道规则是匹配的。例如,如果我将重定向更改为http://google.com,我确实会被重定向到 Google。但是,当使用所写的规则时,它似乎被忽略了,无论我输入什么,我都会得到 404。
我是否犯了一些明显(或神秘)的错误?
编辑:我在发布问题后不久就发现了这一点。我的规则确实是正确的,但我需要在 config/config.php 中更改以下行:
$config['uri_protocol'] = 'AUTO';
至
$config['uri_protocol'] = 'PATH_INFO';
我不会声称确切知道该更改的作用或解决问题的原因。也许有人可以跟进解释。