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


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

我有LAMP服务器在Ubuntu 14.04上运行,一切似乎都配置得很好。唯一的问题是,重写规则在某种程度上被忽略了,而没有发出任何错误。修改.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的帮助。