2011-09-22 75 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] 

看來,垃圾進入將導致此太像循環瘋狂。