我的本地环境运行良好。在 .htaccess 中粘贴了一条测试路线,它按预期工作(将我重新路由到谷歌)。
RewriteEngine on
RewriteRule testpage\.html http://www.google.com [R]
我在我的开发服务器(Unbutu 12.04)上粘贴了同样的东西,它只是给了我一个 Not Found 页面。当我通过运行在开发服务器上验证它时:
sudo a2enmod rewrite
它说“模块重写已启用”。
编辑:它也出现在 phpinfo() 的“加载模块”部分中,自从安装 apache 服务器以来,我已经多次重新启动它。
有任何想法吗?
最佳答案
很可能是因为 mod_rewrite 已启用,但 .htaccess 文件已通过以下方式禁用
AllowOverride None
禁用检查 .htaccess 文件(这会给你一些性能提升,但你必须将你的 mod_rewrite 代码直接放在 apache 配置文件中)
将您的虚拟主机更改为:
AllowOverride All
关于apache - Mod_rewrite 不能在 Ubuntu 服务器上运行(虽然可以在本地运行),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12272328/