2013-06-30 42 views
1

每當我嘗試使用我的.htaccess訪問不存在的文件/文件夾時,它將在日誌中返回500錯誤而不是404以及以下消息:來自不存在的文件/文件夾的錯誤

Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace. 

這裏是代碼造成的問題:

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^([^/]+)/([^/]+)/*$ /$1.php?p=$2 [L] 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^([^/]+)/*$ /$1.php [L] 
</IfModule> 

的代碼轉換網址如下:

http://mysite.com/about -> http://mysite.com/about.php 
http://mysite.com/something/else -> http://mysite.com/something.php?p=else 

一個網址CA使用錯誤真的是任何服務器無法找到例如:

http://mysite.com/Idontexist.php 
http://mysite.com/nosuchfolder 

有誰知道如何防止這種情況?

+0

你能用英文解釋你的.htaccess文件正在做什麼,然後顯示一個表現出這種行爲的URL嗎?很明顯,你的.htaccess文件正在導致重定向循環。 –

+0

@TobyAllen我用它做了什麼更新了這個問題。 – lemondrop

回答

2

你必須添加一個RewriteCond,它檢查Mod_Rewrite是否已經進行了內部重定向,L falg僅停止當前運行,然後.htaccess指令將被重新執行,如果url已被更改(這是這裏的情況):

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_URI} !\.php$ 
RewriteRule ^([^/]+)/([^/]+)/*$ /$1.php?p=$2 [L] 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_URI} !\.php$ 
RewriteRule ^([^/]+)/*$ /$1.php [L] 
</IfModule> 
相關問題