Wordpress的奇怪重定向问题,即使标题在缺少尾部斜杠时是正确的


Odd redirect issue with Wordpress even though Headers are correct when missing trailing slash

嘿,程序员们!

好吧,我敢肯定真的很琐碎,但我就是无法解决这个问题。

基本上(未登录时)并请求没有尾部斜杠的页面浏览器返回

"重定向循环"

错误或在火狐中替代错误,但类似。

Firefox 检测到服务器正在以永远不会完成的方式重定向对此地址的请求。 此问题有时可能是由于禁用或拒绝接受引起的 饼干。

有趣。。。当您进行简单的刷新时,它会加载正常,然后缓存 301 以便之后工作。

好的,这里是响应标头:

http://www.theurl.com/attitude-competition

HTTP/1.1 301 永久移动日期:2013 年 10 月 28 日星期一 23:05:28 GMT 服务器: Apache/2.2.14 (Ubuntu) X-Powered-by: PHP/5.3.2-1ubuntu4.20 X-pingback: http://www.theurl.com/xmlrpc.php 位置: http://www.theurl.com/attitude-competition/变化:接受编码 内容长度: 0 内容类型: 文本/html;字符集=UTF-8

http://www.theurl.com/attitude-competition/

HTTP/1.1 200 OK 日期:2013 年 10 月 28 日星期一 23:05:30 GMT 服务器: Apache/2.2.14 (Ubuntu) X-Powered-By: PHP/5.3.2-1ubuntu4.20 X-Pingback: http://www.theurl.com/xmlrpc.php 链接: ;rel=shortlink 变化: 接受编码传输编码:分块内容类型:文本/html; 字符集=UTF-8

对我来说一切看起来都不错,但我在不同的浏览器中进行了测试,每次都失败了。

编辑

我已经做了一些进一步的研究,这是以管理员身份登录时的标题,它没有同样的问题。

HTTP/1.1 301 永久移动日期:2013 年 10 月 29 日星期二 00:03:20 GMT 服务器: Apache/2.2.14 (Ubuntu) X-Powered-by: PHP/5.3.2-1ubuntu4.20 X-pingback: http://www.theurl.com/xmlrpc.php 到期: 星期三, 11 一月 1984 05:00:00 GMT 缓存控制:无缓存、必须重新验证、最大年龄=0 杂注:无缓存 位置:http://www.theurl.com/attitude-competition/ 变化: 接受编码 内容编码: gzip 内容长度: 20 保持活动状态:超时=15 连接:保持活动状态 内容类型:文本/html; 字符集=UTF-8

编辑 2

更奇怪的是,当Chromes Web Inspector打开时,它工作正常。无法缓存,因为我尝试过隐身和其他浏览器。

有什么想法吗?

# Force Trailing Slash - Beau Bhavik Code START
<IfModule rewrite_module>
  RewriteEngine On
  RewriteBase /
  # If not a real file or directory.
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  # Not a part of the WP admin area.
  RewriteCond %{REQUEST_URI} !(?:^|/)wp'-admin(?:/|$)
  # If there is no trailing slash.
  RewriteCond %{REQUEST_URI} !(?:.*)/$
  # Force a trailing slash on all virtual requests.
  RewriteRule ^(.*)$ /$1/ [QSA,L,R=301]
</IfModule>
# Force Trailing Slash - Beau Bhavik Code END
# Force NO Trailing Slash - Beau Bhavik Code START
<IfModule rewrite_module>
  RewriteEngine On
  RewriteBase /
  # If not a real file or directory.
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  # Not a part of the WP admin area.
  RewriteCond %{REQUEST_URI} !(?:^|/)wp'-admin(?:/|$)
  # If there is a trailing slash.
  RewriteCond %{REQUEST_URI} (?:.*)/$
  # Force NO trailing slash on all virtual requests.
  RewriteRule ^(.*)/$ /$1 [QSA,L,R=301]
</IfModule>
# Force NO Trailing Slash - Beau Bhavik Code END

我会检查你是否与你的服务器没有任何冲突的规则(例如.htaccess或nginx规则),基本上一个试图纠正另一个,从而无限循环。

我还会确保你的重写规则没问题 - 你对永久链接做了什么时髦的事情吗?调试的快速方法是关闭永久链接或将规则更改为其他规则。可能会提供一些线索