htaccess rewrite 给出 LimitInternalRecursion 错误

htaccess rewrite 给出 LimitInternalRecursion 错误

我有一个包含以下代码的 .htaccess 文件

<IfModule mod_rewrite.c>
    Options -MultiViews
    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

但是当我访问我的网站时出现这个错误

[client 127.0.0.1] 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.

LogLevel 调试没有给我回溯,并且我认为增加内部递归的限制是不明智的。

有人遇到过这种类型的错误吗?

答案1

假设请求是/index.html

您的第一个重写条件是“如果请求的 URL 不是目录,则将其重写为重定向到自身并添加斜线。” 因此,URL 将被重写为重定向到/index.html/。 它将再次被重写并添加斜线,依此类推,直到无穷。 这就是您收到错误消息的原因。

答案2

万一未来的人们偶然发现这个......

Request exceeded the limit of 10 internal redirects due to probable configuration error我遇到了类似的问题,我的 Laravel 5.1 项目在浏览器和日志文件中出现 500 个错误。

我可以通过在文件中添加RewriteBase /以下内容来解决此问题。RewriteEngine On.htaccess

希望这可以帮助到别人。

相关内容