WordPress 中的 301 重定向循环 [英] 301 redirect loop in WordPress

查看:64
本文介绍了WordPress 中的 301 重定向循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最初使用 301 重定向 www.example.com/→ www.example.com/wp

Initially used a 301 to redirect www.example.com/ → www.example.com/wp

不幸的是,我没有阅读所有除非您 100% 确定它是永久性的,否则不要使用 301"的全部内容,现在我需要恢复到原始域.

Unfortunately, I didn't read all the 'don't use 301 unless your 100% sure it's permanent' and now I need to revert back to the original domain.

起初,我尝试在管理仪表板的设置/常规中进行常规站点 url/wordpress url 更改.保存在具有原始 301 重定向的根上的旧 .htaccess 上.没用.

At first, I tried to do a regular site url/wordpress url change in Setting/General in the admin dash. Saved over the old .htaccess on the root that had the original 301 redirect. Didn't work.

我将所有内容移至根目录,因为我收到此网页是重定向循环"错误页面.清除所有浏览器上的缓存.仍然得到重定向循环错误页面.

I moved everything to the root directory because I was getting a 'This webpage is a redirect loop' error page. Cleared cache on all browsers. Still getting the redirect loop error page.

在这里检查我的 url 重定向:http://www.digitalcoding.com/工具/url-redirect-check.html

Checked my url redirection here: http://www.digitalcoding.com/tools/url-redirect-check.html

我有两个提示,第一个是顺利通过,第二个是红色的大胖X:
301 永久移动:www.example.com/→ www.example.com
301 检测到另一个重定向:www.example.com

I have two prompts, the first is going through fine, the second is a big fat X in red:
301 Moved Permanently: www.example.com/ → www.example.com
301 Another Redirect Detected: www.example.com

.htaccess 看起来像这样:

.htaccess looks like this:

#Use PHP 5.4
AddType application/x-httpd-php54 .php
<IfModule mod_suphp.c>
suPHP_ConfigPath /opt/php54/lib/php.ini
</IfModule>
ErrorDocument 401 default
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

有什么见解吗?

推荐答案

重定向 301/http://www.example.com/您会遇到无限循环,因为该代码中没有任何内容告诉它不要将 www.example.com 重定向到自身.

Redirect 301 / http://www.example.com/ You get an endless loop because there is nothing in that code to tell it not to redirect www.example.com to itself.

您不能使用重定向指令是正确的,这就是原因;它是无条件的,并且会在您描述的场景中导致循环.

You are correct that you cannot use the Redirect directive, and this is the reason; It is unconditional, and will cause a loop in the scenario you describe.

为了防止循环,您必须找到一种方法来告诉代码不要将 www.example.com 重定向到自身.这可以通过使用 mod_rewrite 来完成,特别是使用 mod_rewrite 中的 RewriteCond 指令来测试请求的主机名并采取相应的行动:

In order to prevent the loop, you must find a way to tell the code not to redirect www.example.com to itself. This can be done by using mod_rewrite, and specifically, the RewriteCond directive in mod_rewrite, to test the requested hostname and act accordingly:

 Options +FollowSymLinks -MultiViews
   RewriteEngine on
   #
   # if requested hostname is non-blank
   RewriteCond %{HTTP_HOST} .
   # and if requested hostname is NOT "www.example.com"
   RewriteCond %{HTTP_HOST} !^www\.example\.com
   # redirect to same object in correct domain
   RewriteRule (.*) http://www.example.com/$1 [R=301,L]

您的服务器可能需要也可能不需要第一个指令选项.如果不需要,实际上可能是不允许的.注释掉你有问题.

The first directive, Options, may or may not be required on your server. If it is not required, it may in fact not be allowed. Comment it out of you have trouble.

第二个指令 RewriteEngine 在 mod_rewrite 代码的顶部需要一次(并且仅一次).

The second directive, RewriteEngine, is required once (and only once) at the top of your mod_rewrite code.

第三个指令,第一个 RewriteCond,仅在您不使用基于名称的虚拟(共享)服务器时才需要.如果客户端不随其请求发送主机"标头,则它可以防止无限循环.由于没有主机"标头就不可能访问基于名称的虚拟服务器,因此在基于名称的虚拟服务器上不需要此行.把它留在里面没有坏处,只是需要一点时间来处理.

The third directive, the first RewriteCond, is only required if you do not use a name-based virtual (shared) server. It prevents an infinite loop if the client does not send a "Host" header with its request. Since it is impossible to access a name-based virtual server without a "Host" header, this line is not required on a name-based virtual server. No harm will come from leaving it in, except that it takes a little time to process it.

请注意,此代码还将example.com"重定向到www.example.com",因此也用于规范化您的主域名,防止排名稀释在域的两个变体上出现重复的内容.

Note that this code will also redirect "example.com" to "www.example.com", and so serves to canonicalize your main domain name as well, preventing ranking dilution from having duplicate content on two variations of the domain.

这篇关于WordPress 中的 301 重定向循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆