Debian squeeze 中的重写重定向问题

Debian squeeze 中的重写重定向问题

我的服务器操作系统是 debian squeeze。我在网站的 htaccess 文件中用以下几行将非 www 重定向到 www:

RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

但它在 Firefox 中导致此错误:

  The page isn't redirecting properly

  Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

  This problem can sometimes be caused by disabling or refusing to accept
cookies.

当我在 htaccess 中注释这些行时,mysite 会出现,但不是 www 格式。我确信它之前在 Ubuntu 上运行良好。但我不知道为什么它现在不起作用了。你能帮助我吗?

答案1

可能是因为您使用了 301 重定向,所以您看到的是缓存结果。如果您创建了错误的重定向并对其进行了测试,然后进行了修复,您仍然会在 Firefox 等浏览器中看到旧的缓存结果。使用 进行测试curl --include http://www.example.com

如果使用 时仍遇到同样的问题curl,则问题很可能出在您用 替换的位上www.example.com。如果这两个字符串不完全相同,您将遇到重定向循环。

在你当然它们是正确的,然后才切换到 301。

相关内容