修改.htaccess后,CodeIgniter 2无法再使用PATH_INFO

时间:2011-09-10 19:10:52

标签: .htaccess codeigniter mod-rewrite codeigniter-2 pathinfo

我是CI的新手,我正试图从网址中删除恼人的“index.php”。这是我正在使用的.htaccess:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]

如您所见,我必须使用QUERY_STRING使新网址生效(请注意index.php之后的问号)。当我尝试使用PATH_INFO时(即没有问号),我只会收到No input file specified错误。

这很好,如果必须的话,我可以使用QUERY_STRING,但我不明白这个问题因为我在开始玩重写之前就已经使用了PATH_INFO了 - 即默认的“example.com/index.php/controller/function”正在运行,并使用PATH_INFO AFAIK。

有谁知道为什么htaccess在我的例子中打破了PATH_INFO?抱歉这个愚蠢的问题。

1 个答案:

答案 0 :(得分:2)

试试这个:

RewriteEngine   on
RewriteCond     %{REQUEST_FILENAME} !-d
RewriteCond     %{REQUEST_FILENAME} !-f
RewriteRule     .* index.php/%{REQUEST_URI}   [L]

上面的重写规则似乎适用于我正在处理的应用程序......它们会传递正确的GET请求以及正确的PATH_INFO值。