mod_rewrite!-f和!-d被忽略.php扩展名

我在Apache 2服务器上有一个.htaccess文件:

<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> 

这些规则可以按照预期的方式处理任何请求,将不存在的文件或目录交给index.php程序进行处理。

如果请求的文件存在,例如服务器上的任何.txt或.js文件,规则也会绕过redirect。

但是任何以.php结尾的文件都不能正确处理。 文件存在,但是!-f和!-d规则被忽略。 只需将扩展名更改为.phpt并请求相同的文件(将“t”添加到最后)即可显示文件内容。

任何线索为什么只有.php文件会跳过!-f和!-d规则?

这个mod_rewrite的工作更容易预测一对:Cond + Rule你的路线:

 RewriteRule ^index\.php$ - [L] 

已经与下面的行匹配,因为index.php是一个文件。

尝试:

 <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule .* /index.php [L] </IfModule> 

我猜可能是 。 将只匹配一个字符,我改变了。 至 。*