使用Windows 7上安装的Apache2,我使用下面的htaccess配置从codeigniter url中删除index.php:
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
有人可以告诉我为什么上面的配置在 ubuntu 上不起作用吗? 我已使用 sudo a2enmod rewrite 启用 mod 重写。谢谢
最佳答案
这可能是因为 ubuntu 服务器设置为传递 PATH_INFO,这意味着您不需要查询字符串。您可能只需从规则中删除 ?
就可以了:
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
# no query string ----------^
关于.htaccess - 使用 htaccess 文件删除 ubuntu 上 codeigniter 中的 index.php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18365829/