php 请求超出了 10 次内部重定向的限制

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19071324/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 18:47:42  来源:igfitidea点击:

Request exceeded the limit of 10 internal redirects

phpapache.htaccesscodeignitererror-handling

提问by max

My website has been slowed down a little last couple of days. I've looked into my error log and found lots of these:

我的网站最近几天变慢了。我查看了我的错误日志,发现了很多这些:

[Mon Sep 30 00:09:53 2013] [error] [client 66.249.66.205] 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.
[Mon Sep 30 00:09:53 2013] [debug] core.c(3120): [client 66.249.66.205] r->uri = /home/mysitecom/domains/mysite.com/public_html/index.php
[Mon Sep 30 00:09:53 2013] [debug] core.c(3126): [client 66.249.66.205] redirected from r->uri = /home/mysitecom/domains/mysite.com/public_html/index.php
[Mon Sep 30 00:09:53 2013] [debug] core.c(3126): [client 66.249.66.205] redirected from r->uri = /home/mysitecom/domains/mysite.com/public_html/index.php
[Mon Sep 30 00:09:53 2013] [debug] core.c(3126): [client 66.249.66.205] redirected from r->uri = /home/mysitecom/domains/mysite.com/public_html/index.php
[Mon Sep 30 00:09:53 2013] [debug] core.c(3126): [client 66.249.66.205] redirected from r->uri = /home/mysitecom/domains/mysite.com/public_html/index.php
[Mon Sep 30 00:09:53 2013] [debug] core.c(3126): [client 66.249.66.205] redirected from r->uri = /home/mysitecom/domains/mysite.com/public_html/index.php
[Mon Sep 30 00:09:53 2013] [debug] core.c(3126): [client 66.249.66.205] redirected from r->uri = /home/mysitecom/domains/mysite.com/public_html/index.php
[Mon Sep 30 00:09:53 2013] [debug] core.c(3126): [client 66.249.66.205] redirected from r->uri = /home/mysitecom/domains/mysite.com/public_html/index.php
[Mon Sep 30 00:09:53 2013] [debug] core.c(3126): [client 66.249.66.205] redirected from r->uri = /home/mysitecom/domains/mysite.com/public_html/index.php
[Mon Sep 30 00:09:53 2013] [debug] core.c(3126): [client 66.249.66.205] redirected from r->uri = /home/mysitecom/domains/mysite.com/public_html/index.php
[Mon Sep 30 00:09:53 2013] [debug] core.c(3126): [client 66.249.66.205] redirected from r->uri = /images/2013/02/600x376_0.076827001313237200_pixnaz_ir_1.jpg


How can I find what is causing this?

我怎样才能找到导致这种情况的原因?

It seems a loop around index.php, with the exception of the last one which is an image, most likely linked within one of my pages (not index).

这似乎是一个围绕 index.php 的循环,除了最后一个是图像,很可能链接在我的一个页面(不是索引)中。

I'm using codeigniter, which is a mvc framework and everything goes trough the index.php file, so it's a bit harder to understand where it goes wrong.

我正在使用 codeigniter,它是一个 mvc 框架,所有内容都通过 index.php 文件进行,因此很难理解哪里出错了。

Apparently it has something to do with .htaccess (it's been mentioned in couple of blogs).

显然它与 .htaccess 有关(在几个博客中提到过)。

Here is my .htaccess

这是我的 .htaccess

<IfModule mod_rewrite.c>
    RewriteEngine On

    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ index.php?/ [L]

    #When your application folder isn't in the system folder
    #This snippet prevents user access to the application folder
    #Submitted by: Fabdrol
    #Rename 'application' to your applications folder name.
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ index.php?/ [L]

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/ [L]
</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin

    ErrorDocument 404 index.php
</IfModule> 
AddType image/x-windows-bmp bmp


I did some changes to my .htaccess (basically I've removed to top conditions before the last block) and now I get this:

我对我的 .htaccess 做了一些更改(基本上我已经在最后一个块之前移除了最高条件),现在我得到了这个:

[Wed Oct 02 00:10:07 2013] [error] [client 66.249.74.60] 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.
[Wed Oct 02 00:10:07 2013] [debug] core.c(3120): [client 66.249.74.60] r->uri = /home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/images/2013/07/irwm_mysite_47b49a36d251fea382ba6b494fd3532ea75c78e6.jpg
[Wed Oct 02 00:10:07 2013] [debug] core.c(3126): [client 66.249.74.60] redirected from r->uri = /home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/images/2013/07/irwm_mysite_47b49a36d251fea382ba6b494fd3532ea75c78e6.jpg
[Wed Oct 02 00:10:07 2013] [debug] core.c(3126): [client 66.249.74.60] redirected from r->uri = /home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/images/2013/07/irwm_mysite_47b49a36d251fea382ba6b494fd3532ea75c78e6.jpg
[Wed Oct 02 00:10:07 2013] [debug] core.c(3126): [client 66.249.74.60] redirected from r->uri = /home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/images/2013/07/irwm_mysite_47b49a36d251fea382ba6b494fd3532ea75c78e6.jpg
[Wed Oct 02 00:10:07 2013] [debug] core.c(3126): [client 66.249.74.60] redirected from r->uri = /home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/images/2013/07/irwm_mysite_47b49a36d251fea382ba6b494fd3532ea75c78e6.jpg
[Wed Oct 02 00:10:07 2013] [debug] core.c(3126): [client 66.249.74.60] redirected from r->uri = /home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/images/2013/07/irwm_mysite_47b49a36d251fea382ba6b494fd3532ea75c78e6.jpg
[Wed Oct 02 00:10:07 2013] [debug] core.c(3126): [client 66.249.74.60] redirected from r->uri = /home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/images/2013/07/irwm_mysite_47b49a36d251fea382ba6b494fd3532ea75c78e6.jpg
[Wed Oct 02 00:10:07 2013] [debug] core.c(3126): [client 66.249.74.60] redirected from r->uri = /home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/images/2013/07/irwm_mysite_47b49a36d251fea382ba6b494fd3532ea75c78e6.jpg
[Wed Oct 02 00:10:07 2013] [debug] core.c(3126): [client 66.249.74.60] redirected from r->uri = /home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/images/2013/07/irwm_mysite_47b49a36d251fea382ba6b494fd3532ea75c78e6.jpg
[Wed Oct 02 00:10:07 2013] [debug] core.c(3126): [client 66.249.74.60] redirected from r->uri = /home/mysite/domains/mysite.com/public_html/index.php/img/images/2013/07/irwm_mysite_47b49a36d251fea382ba6b494fd3532ea75c78e6.jpg
[Wed Oct 02 00:10:07 2013] [debug] core.c(3126): [client 66.249.74.60] redirected from r->uri = /images/2013/07/irwm_mysite_47b49a36d251fea382ba6b494fd3532ea75c78e6.jpg

Now it seems there is the imgdirectory in the mix, but I dont have that directory at all. There used to be a subdomain which I used for images with this address.

现在似乎img混合中有该目录,但我根本没有该目录。曾经有一个子域,我用于具有此地址的图像。

img.mysite.com => mysite.com/files/images/

I don't use it anymore because of some slowness and complications. Now I just use the real path to images.

我不再使用它了,因为有些缓慢和复杂。现在我只使用图像的真实路径。

Why do i get this subdomain in the loop? I don't have access to the guy who configured this server. Could it be some config / setting that he has done?

为什么我在循环中得到这个子域?我无权访问配置此服务器的人。可能是他所做的一些配置/设置?

回答by anubhava

To prevent infinite looping add an extra RewriteCondline on top of your rule like this:

为了防止无限循环RewriteCond,在您的规则之上添加额外的一行,如下所示:

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/ [L]

RewriteCond %{ENV:REDIRECT_STATUS} ^$prevents looping by checking an internal mod_rewritevariable REDIRECT_STATUSwhich is set to 200 after first successful internal redirect.

RewriteCond %{ENV:REDIRECT_STATUS} ^$通过检查在第一次成功内部重定向后设置为 200的内部mod_rewrite变量REDIRECT_STATUS来防止循环。

Reference: Apache mod_rewrite Introduction

参考:Apache mod_rewrite 介绍

回答by hakre

The last block:

最后一块:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/ [L]

Is most likely re-injecting a changed request URI over and over again which could cause such an internal redirect error. Check the error log with debugging level enabled to trace each redirect step, it makes things much more visible and will tell you exactly which redirect rules are triggering it.

很可能一遍又一遍地重新注入已更改的请求 URI,这可能会导致此类内部重定向错误。在启用调试级别的情况下检查错误日志以跟踪每个重定向步骤,它使事情更加明显,并且会确切地告诉您哪些重定向规则正在触发它。

For a detailed description and how to prevent the re-injection, please see:

有关详细说明以及如何防止重新注入,请参阅:

The solution outlined thereactually should do it in your case as well. It's pretty much the same, even the file-names are identical.

那里列出解决方案实际上也应该适用于您的情况。它几乎相同,甚至文件名也相同。

回答by mamdouh alramadan

Looking to your htaccess I see that you use it to remove index.phpfrom your url, but you are missing the RewriteBase, you can add it after the RewriteEngine Ondirectly like this:

查看您的 htaccess,我看到您使用它index.php从您的 url 中删除,但是您缺少RewriteBase,您可以RewriteEngine On像这样直接在 之后添加它:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/ [L]

    #When your application folder isn't in the system folder
    #This snippet prevents user access to the application folder
    #Submitted by: Fabdrol
    #Rename 'application' to your applications folder name.
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/ [L]

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/ [L]
</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin

    ErrorDocument 404 /index.php
</IfModule> 
AddType image/x-windows-bmp bmp

So, RewriteBase /will be valid if your application/website is not on a subdomain. However, if it is then you might need to add the folder name after the /symbol.

因此,RewriteBase /如果您的应用程序/网站不在subdomain. 但是,如果是,则您可能需要在/符号后添加文件夹名称。

回答by vinicius.olifer

Maybe it is a dummie awnser, but I just empty my .htaccess and configure permalinks again. Everything works after that.

也许它是一个虚拟的 awnser,但我只是清空了我的 .htaccess 并再次配置了永久链接。之后一切正常。

回答by mikiqex

You can also use the END flag, instead of the L flag:

您还可以使用END 标志,而不是 L 标志:

RewriteRule ^(.*)$ index.php?/ [END]

Using the [END] flag terminates not only the current round of rewrite processing (like [L]) but also prevents any subsequent rewrite processing from occurring in per-directory (htaccess) context.

This does not apply to new requests resulting from external redirects.

使用 [END] 标志不仅可以终止当前轮次的重写处理(如 [L]),还可以防止在每个目录 (htaccess) 上下文中发生任何后续的重写处理。

这不适用于由外部重定向产生的新请求。

回答by Neel Prakash

I commented out the "RewriteBase /drupal" in my .htaccess file? present in drupal root folder. It works for me.

我在 .htaccess 文件中注释掉了“RewriteBase /drupal”?存在于 drupal 根文件夹中。这个对我有用。

回答by foxdanni

I had some performance issues in Apache when the loglevel was debug ... Moving back to Error mode speedup the requests

当日志级别被调试时,我在 Apache 中遇到了一些性能问题......回到错误模式加速了请求