2011-08-12 77 views
0

我正在运行Apache 2.2.19服务器,并且在处理.html扩展时遇到了mod_rewrite问题。 .php URL清理工作正常,但不是.html。在错误日志,我得到这个:mod_rewrite .html扩展

[Fri Aug 12 04:17:36 2011] [error] [client (AN IP ADDRESS)] script '(A DIRECTORY PATH)/forbidden.php' not found or unable to stat, referer: (MY WEBSITE) 
[Fri Aug 12 04:17:38 2011] [error] [client (AN IP ADDRESS)] script '(A DIRECTORY PATH)/notfound.php' not found or unable to stat, referer: (MY WEBSITE) 

其中省略出于安全和隐私的原因(这是由文本括号代替)的一些信息。禁止和未发现实际上是带有HTML扩展名的HTML文件,但由于某些原因,mod_rewrite正试图访问.php文件。如果没有将文件扩展名更改为.php的简单方法,我怎么才能让mod_rewrite查看正确的扩展名并对其进行评估,而不是将HTML文件视为具有.php扩展名?

非常感谢!

下面是相关的代码,这是在httpd.conf:

RewriteEngine on 
Options +FollowSymlinks 
RewriteCond %{REQUEST_URI} !(\.[^./]+)$ 
RewriteCond %{REQUEST_FILENAME} !-d 

RewriteCond %{REQUEST_FILENAME} \.html-f 
RewriteRule (.*) /$1.html [L] 

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+\.)+html\ HTTP 
RewriteRule ^([^\.]+)\. $1 [R=302,L] 

RewriteCond %{REQUEST_FILENAME} \.php-f 
RewriteCond %{REQUEST_FILENAME} phpinfo 
RewriteRule (.*) /$1.php [L] 

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+\.)+php\ HTTP 
RewriteRule ^([^\.]+)\. $1 [R=302,L] 

回答

1

为.html文件的规则有2个附加条件: RewriteCond %{REQUEST_URI} !(\.[^./]+)$ RewriteCond %{REQUEST_FILENAME} !-d

我第一个想到的原因造成的问题,因为你正在寻找文件名中的.html,但是uri不应该包含。

+0

没有。这根本不会造成任何问题。无论出于何种原因,mod_rewrite只会尝试查找.php扩展名,因此会在错误日志中给我提供文件未找到错误。 – bolts