【发布时间】:2011-09-22 15:36:20
【问题描述】:
我有一个使用 Mod_Rewrite 的 .htaccess 文件,但如果有人在 URL 中放入垃圾内容,它会生成 500 错误并显示我的所有 mod 信息,我会遇到问题。我想阻止它生成 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 Internal Server Error 错误”,我找不到这是从哪里提取的。
[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
这个循环发生在哪里?没看到。
【问题讨论】:
-
查看服务器的错误日志——它会有更多关于错误原因的详细信息。您在浏览器中获得的设计非常模糊,因为 500 错误详细信息可能会泄露不应公开的服务器/代码信息。
-
[Thu Sep 22 10:44:42 2011] [error] [client 74.84.118.99] 由于可能的配置错误,请求超出了 10 个内部重定向的限制。如有必要,使用“LimitInternalRecursion”增加限制。使用'LogLevel debug'来获得回溯。,referer:streatoronized.org - - 当垃圾放入其中时,Htaccess 一定会导致大量重定向。
-
所以...如果有人输入垃圾网址,您的重写就会陷入无限循环。您必须添加一些东西来处理虚假 url 案例以防止这种情况发生。
-
我只是将我的日志置于调试模式,并且多次将 .php 附加到垃圾上。我不确定我的 .htaccess 是在哪里引起的。 (见上文)
-
显而易见的方法:开始注释掉 .htaccess 的各个块并查看是否/何时发生变化。
标签: php apache .htaccess mod-rewrite