重写debian中的redirect问题

我的服务器操作系统是debian挤压。 我有这些行来redirect非www到我的网站的htaccess文件中的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上运行良好。 但我不知道为什么现在不行。 你能帮我吗?

这可能是因为你正在使用301redirect,你会看到一个caching的结果。 如果您创build了错误的redirect并对其进行了testing,然后对其进行了修复,您仍然可以在Firefox等浏览器中获得旧的caching结果。 用curl --include http://www.example.com做你的testing – 包括curl --include http://www.example.com

如果你仍然遇到与curl相同的问题,这个问题很可能在你用www.example.com取代的位上。 如果这两个string不完全相同,你将得到一个redirect循环。

使用302redirect也是值得的,直到你确定它们是正确的,然后才切换到301。