当其他功能正常工作时,Apache 重写规则被忽略

Apache rewrite rule is getting ignored while other functions are working properly

我在 Ubuntu 14.04 上有 LAMP 服务器 运行,一切似乎都已配置好。唯一的问题是,重写规则以某种方式被忽略而没有发出任何错误。修改 .htaccess 文件后,页面会像往常一样重新加载。我想做的是使用以下代码将所有流量路由到 index.php:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]

其他规则运行正常,例如。如果我添加 deny from all 并重新加载页面,我会立即收到错误消息。所有文件和文件夹都位于 /var/www/ 根目录中。我不知道这里缺少什么,我花了几个小时调试这个问题而没有解决方案:(.

.只会匹配一个字符。尝试使用 .* 来匹配任何内容。

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php [L]

我找到了一个将所有流量重定向到 index.php 的解决方案,方法是将文档根目录指向 index.php:

<VirtualHost *:80>
ServerAdmin admin@example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com/index.php
</VirtualHost>

感谢@Chris 的帮助。