2011-09-22 65 views
2

我有一个使用Mod_Rewrite的.htaccess文件,但如果有人在URL中输入垃圾,它会产生500错误,并显示我所有的Mod信息。我想阻止它生成500错误或将该错误转发到其他页面。我努力了。Mod Rewrite 500错误更正

Error Document 500 /index.php 

...但它不工作或重定向。

这里是我的全部的.htaccess

Options -Indexes 
Options +FollowSymlinks 

ErrorDocument 500 /index.php 

RewriteEngine On 

RewriteRule ^BEARS bears.php?page=bears [NC,L] 

RewriteCond %{http_host} ^www.domian.org/login.php [NC] 
RewriteRule ^(.*)$ https://www.domian.org/login.php [R=301,L] 

RewriteCond %{http_host} ^domian.com [NC] 
RewriteRule ^(.*)$ http://www.domian.org/$1 [R=301,L] 

RewriteCond %{http_host} ^domian.org [NC] 
RewriteRule ^(.*)$ http://www.domian.org/$1 [R=301,L] 

RewriteCond %{http_host} ^www.domian.com [NC] 
RewriteRule ^(.*)$ http://www.domian.org/$1 [R=301,L] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.+)/DB/(.+)/page/(.+)$ $1.php?DB=$2&page=$3 [L,QSA] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.+)/DB/(.+)$ $1.php?DB=$2 [L,QSA] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.+)/(.+)$ $1.php?page=$2 [L,QSA] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.+)$ $1.php?page=$1 [L,QSA] 

也没有人知道正在从产生的500错误。我知道错误文件夹中有错误文档,但是此错误说“此外,尝试使用ErrorDocument来处理请求时遇到500内部服务器错误错误”,并且我无法找到它从哪里拉。

[Thu Sep 22 11:11:40 2011] [debug] core.c(3071): [client 74.84.118.99] redirected from r->uri = /test.html.php.php.php.php.php.php.php.php.php 
[Thu Sep 22 11:11:40 2011] [debug] core.c(3071): [client 74.84.118.99] redirected from r->uri = /test.html.php.php.php.php.php.php.php.php 
[Thu Sep 22 11:11:40 2011] [debug] core.c(3071): [client 74.84.118.99] redirected from r->uri = /test.html.php.php.php.php.php.php.php 
[Thu Sep 22 11:11:40 2011] [debug] core.c(3071): [client 74.84.118.99] redirected from r->uri = /test.html.php.php.php.php.php.php 
[Thu Sep 22 11:11:40 2011] [debug] core.c(3071): [client 74.84.118.99] redirected from r->uri = /test.html.php.php.php.php.php 
[Thu Sep 22 11:11:40 2011] [debug] core.c(3071): [client 74.84.118.99] redirected from r->uri = /test.html.php.php.php.php 
[Thu Sep 22 11:11:40 2011] [debug] core.c(3071): [client 74.84.118.99] redirected from r->uri = /test.html.php.php.php 
[Thu Sep 22 11:11:40 2011] [debug] core.c(3071): [client 74.84.118.99] redirected from r->uri = /test.html.php.php 
[Thu Sep 22 11:11:40 2011] [debug] core.c(3071): [client 74.84.118.99] redirected from r->uri = /test.html.php 
[Thu Sep 22 11:11:40 2011] [debug] core.c(3071): [client 74.84.118.99] redirected from r->uri = /test.html 

这个循环在哪里发生?没有看到它。

+2

看看服务器的错误日志 - 它会有更多关于错误原因的详细信息。您在浏览器中获得的设计非常模糊,因为500错误细节可能泄漏不应公开的服务器/代码信息。 –

+0

[Thu Sep 22 10:44:42 2011] [error] [client 74.84.118.99]由于可能的配置错误,请求超出了10个内部重定向的限制。如果需要,使用'LimitInternalRecursion'来增加限制。使用'LogLevel debug'来获取回溯。,引用:http://www.streatoronized.org/ - 当垃圾被放入时,Htaccess必须引起大量的重定向。 –

+1

所以......如果有人输入垃圾网址,你的重写就进入了无限循环。你将不得不添加一些东西来处理伪造的url案例,以防止这种情况。 –

回答

1

要扩大你的答案,但更准确地说这条线:

RewriteRule ^(.+)$ $1.php?page=$1 [L,QSA] 

不检查,看看是否该文件名已与PHP结束。

它循环,添加.php.php.php.php,直到达到最大值(检查apache/logs/error.log),然后只是服务原来的页面,这恰好存在,所以看起来一切正常。

为了解决这个问题,添加如下内容:

RewriteRule ^(.*)\.php$ - [L] 

其停止([L])如果地址与.php结束。

1

我想我会把问题的解决方案放在这里,以防万一有人遇到同样的问题。

我的问题代码为这个片段中......

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.+)$ $1.php?page=$1 [L,QSA] 

看来,垃圾进入将导致此太像循环疯狂。