CodeIgniter 的重写器不起作用 [英] Rewriterule for CodeIgniter not working
问题描述
我已经安装了一个干净的 Apache2(加上 PHP 和 MySQL)服务器并在 apache 配置中启用了 mod_rewrite
.我添加了 .htaccess
文件以从 url 中删除 index.php,如 CodeIgniter wiki 中所述.
I have installed a clean Apache2 (plus PHP & MySQL) server and enabled the mod_rewrite
in the apache config.
I added the .htaccess
file to remove the index.php from the url as described in the CodeIgniter wiki.
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
我将此文件放在网站的根目录中.
I placed this file in the website's root.
当我尝试访问 url mydomain.local/index.php/welcome
然后我得到 CodeIgniter 的默认页面.但是当我尝试通过 mydomain.local/welcome
访问同一页面时,我得到了 404 页面.
When I try to access the url mydomain.local/index.php/welcome
then I get the default page of CodeIgniter. But when I try to access the same page through mydomain.local/welcome
then I get the 404 page.
如何检查整个重写规则是否有效?为什么它不起作用?
How can I check if the whole rewrite rule is working? And why isn't it working?
推荐答案
我找到了解决方案.Apache 配置不允许运行 htaccess 文件.所以我必须将目录上的 AllowOverride
标志设置为 AllowOverride ALL
.
I found the solution. The htaccess file wasn't allowed to run by the Apache config. So I had to set the AllowOverride
flag on the directory to AllowOverride ALL
.
感谢大家的帮助!
这篇关于CodeIgniter 的重写器不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!