.htaccess を使用して存在しないファイル/フォルダーにアクセスしようとすると、404 ではなく 500 エラーが返され、ログに次のメッセージが記録されます。
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>
このコードは、次のように URL を変換します。
http://mysite.com/about -> http://mysite.com/about.php
http://mysite.com/something/else -> http://mysite.com/something.php?p=else
エラーの原因となる URL は、実際にはサーバーが見つけられないものです。
http://mysite.com/Idontexist.php
http://mysite.com/nosuchfolder
これを防ぐ方法を知っている人はいますか?