避免迴圈式的網址重寫錯誤: Request exceeded the limit of 10 internal redirects


apache

Request exceeded the limit of 10 internal redirects

查看 Apache 的 error log (Amazon EC2 Linux System 位於 /var/log/httpd/error_log 路徑)

發現有許多下面這樣的錯誤

Request exceeded the limit of 10 internal redirects due to probable configuration error. Use ‘LimitInternalRe
cursion’ to increase the limit if necessary. Use ‘LogLevel debug’ to get a backtrace.

意思就是說請求超過 10 次的內部轉址造成錯誤,可以更改 LimitInternalRecursion 這個設定值來提高限制,並且建議打開 debug 記錄以了解整個內部轉址過程

打開 error log 的 debug 模式

依建議打開 debug 模式,找到 httpd.conf 並編輯它

找到

LogLevel warn

這是默認的警告訊息模式

改為下面的 debug 模式

LogLevel debug

   

過段時間再觀察 error log ,發現 Request exceeded the limit of 10 internal redirects 後面接著如下錯誤訊息

[Thu Aug 14 07:50:43 2014] [debug] core.c(3121): [client 65.55.215.44] r->uri = /index.php
[Thu Aug 14 07:50:43 2014] [debug] core.c(3127): [client 65.55.215.44] redirected from r->uri = /index.php
[Thu Aug 14 07:50:43 2014] [debug] core.c(3127): [client 65.55.215.44] redirected from r->uri = /index.php
[Thu Aug 14 07:50:43 2014] [debug] core.c(3127): [client 65.55.215.44] redirected from r->uri = /index.php
[Thu Aug 14 07:50:43 2014] [debug] core.c(3127): [client 65.55.215.44] redirected from r->uri = /index.php
[Thu Aug 14 07:50:43 2014] [debug] core.c(3127): [client 65.55.215.44] redirected from r->uri = /index.php
[Thu Aug 14 07:50:43 2014] [debug] core.c(3127): [client 65.55.215.44] redirected from r->uri = /index.php
[Thu Aug 14 07:50:43 2014] [debug] core.c(3127): [client 65.55.215.44] redirected from r->uri = /index.php
[Thu Aug 14 07:50:43 2014] [debug] core.c(3127): [client 65.55.215.44] redirected from r->uri = /index.php
[Thu Aug 14 07:50:43 2014] [debug] core.c(3127): [client 65.55.215.44] redirected from r->uri = /index.php
[Thu Aug 14 07:50:43 2014] [debug] core.c(3127): [client 65.55.215.44] redirected from r->uri = /robots.txt

這個重複的內部轉換造成無止盡的迴圈

可以改變 rewrite 設置來避免這種情況

改寫 Rewrite 規則 (.htaccess)

要改寫重寫規則要找到 .htaccess (位於網站根路徑)

以下是 WordPress 安裝完後的默認重寫設置

RewriteEngine on
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.(php|html|htm)\ HTTP/
RewriteRule ^(.*)$  http://abc.com/ [R=301,L]

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

在前面加上下面這兩行

RewriteCond %{ENV:REDIRECT_STATUS} 200

RewriteRule ^.*$ – [L]

完整如下:

RewriteEngine on
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^.*$ - [L]

RewriteEngine on
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.(php|html|htm)\ HTTP/
RewriteRule ^(.*)$  http://abc.com/ [R=301,L]

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

避免迴圈式的網址重寫錯誤 延伸閱讀

(*) 【SEO筆記】 網址規範化之網站首頁指向同一網頁內容

(*) Amazon EC2 t1.micro 免費實例崩潰當機! 真的不夠用嗎? Amazon EC2 + Apache + PHP + MySQL 系統調教

本文地址:避免迴圈式的網址重寫錯誤: Request exceeded the limit of 10 internal redirects
內容對你有幫助嗎? 臉書分享:
分享到:

發表迴響

您的電子郵件位址並不會被公開。 必要欄位標記為 *

*

您可以使用這些 HTML 標籤與屬性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

交換連結: Liang's Blog |