我在位于 /var/www/html/
的文档根目录中创建了一个 .htaccess 文件,以重写 Codeigniter 的 URL,从所有页面的 URL 中删除“index.php”。
例如更改 URL 来自
http://myhost/index.php/controller/function
到
http://myhost/controller/function`
这是我的`/var/www/html/.htaccess 的代码
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
我从谷歌搜索中得到了很多启用 mod-rewrite 模块的建议,但我可以在我的 httpd.conf
中看到它已经启用。
LoadModule rewrite_module modules/mod_rewrite.so
这在运行 Debian 7 (Apache/2.4.4) 的本地系统上运行完美。
如有任何帮助,我们将不胜感激。 :)
最佳答案
您还需要指定可以使用它的位置。例如,在/etc/httpd/conf/httpd.conf 中,您应该看到如下内容:
<Directory "/var/www/html">
...lots of text...
</Directory>
确保有:
<Directory "/var/www/html">
AllowOverride All
</Directory>
关于linux - Codeigniter URL 重写 .htaccess 在 CentOS 上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20710569/