wordpress Apache 2.4 - 由于可能的配置错误,请求超出了 10 个内部重定向的限制

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22756796/
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-09-08 19:30:52  来源:igfitidea点击:

Apache 2.4 - Request exceeded the limit of 10 internal redirects due to probable configuration error

wordpressapache.htaccessrewrite

提问by iltdev

I'm running Apache 2.4 (64bit) and PHP 5.4.15 on windows Server 2008 R2 Enterprise and have noticed the following error in the Apache error log:

我在 Windows Server 2008 R2 Enterprise 上运行 Apache 2.4(64 位)和 PHP 5.4.15,并在 Apache 错误日志中注意到以下错误:

AH00124: 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.

I have a multisite install of WordPress running and I think the error is coming from an error in the htaccess rewrites.

我有一个多站点安装的 WordPress 正在运行,我认为该错误来自 htaccess 重写中的错误。

Looking at this post: Request exceeded the limit of 10 internal redirects due to probable configuration error.?

查看这篇文章: 由于可能的配置错误,请求超出了 10 个内部重定向的限制。?

They suggest to replace this:

他们建议替换这个:

# BEGIN Wordpress
<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.php [L]
</IfModule>
# END WordPress

with this piece of code, courtesy of Scott Yang:

这段代码,由 Scott Yang 提供:

<IfModule mod_rewrite.c>
   RewriteEngine On
   RewriteBase /
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^(.+)$ /index.php/ [L,QSA]
</IfModule>

However, my WordPress htaccess looks a little different so I dont just want to replace my code just in case I inadvertently replace something that I need.

但是,我的 WordPress htaccess 看起来有点不同,所以我不想替换我的代码,以防万一我不小心替换了我需要的东西。

Here is my htaccess:

这是我的 htaccess:

# BEGIN WordPress
<IfModule mod_rewrite.c>
Options +FollowSymLinks -MultiViews
Header set Access-Control-Allow-Origin "*"
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*)  [L]
RewriteRule ^(.*\.php)$  [L]
RewriteRule . index.php [L]
</IfModule>
# END WordPress

Can anyone suggest what I need to change?

谁能建议我需要改变什么?

采纳答案by anubhava

You're getting into looping most likely due to these rules:

由于这些规则,您很可能会进入循环:

RewriteRule ^(.*\.php)$  [L]
RewriteRule ^(wp-(content|admin|includes).*)  [L]

Just comment it out and try again in a new browser.

只需将其注释掉,然后在新浏览器中重试。

回答by Justin Samuel

This problem can be caused by requests for certain files that don't exist. For example, requests for files in wp-content/uploads/ where the file does not exist.

此问题可能是由对某些不存在的文件的请求引起的。例如,请求 wp-content/uploads/ 中不存在文件的文件。

If this is the situation you're seeing, you can solve the problem by going to .htaccess and changing this line:

如果这是您所看到的情况,您可以通过转到 .htaccess 并更改此行来解决问题:

RewriteRule ^(wp-(content|admin|includes).*)  [L]

to:

到:

RewriteRule ^(wp-(content|admin|includes).*) - [L]

The underlying issue is that the rule above triggers a rewrite to the exact same url with a slash in front and because there was a rewrite, the newly rewritten request goes back through the rules again and the same rule is triggered. By changing that line's "$1" to "-", no rewrite happens and so the rewriting process does not start over again with the same URL.

潜在的问题是,上面的规则触发了对前面带有斜杠的完全相同的 url 的重写,并且因为有重写,新重写的请求再次通过规则返回并触发相同的规则。通过将该行的“$1”更改为“-”,不会发生重写,因此重写过程不会使用相同的 URL 重新开始。

It's possible that there's a difference in how apache 2.2 and 2.4 handle this situation of only-difference-is-a-slash-in-front and that's why the default rules provided by WordPress aren't working perfectly.

apache 2.2 和 2.4 处理这种只有差异是前斜线的情况的方式可能有所不同,这就是 WordPress 提供的默认规则无法完美运行的原因。

回答by Tarun Gupta

Solved this by adding following

通过添加以下内容解决了这个问题

RewriteCond %{ENV:REDIRECT_STATUS} 200 [OR]
 RewriteCond %{REQUEST_FILENAME} -f [OR]
 RewriteCond %{REQUEST_FILENAME} -d
 RewriteRule ^ - [L]