Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

My server os is debian squeeze. I have these lines to redirect non-www to www in htaccess file of my website:

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

but it cause this error in 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.

when I comment those lines in htaccess mysite appears but in non-www format. I'm sure it works well before on the Ubuntu . but I don't know why it doesn't work now. would you help me?

share|improve this question
add comment

1 Answer

It may be that because you are using a 301 redirect, you are seeing a cached result. If you created the wrong redirect and tested it and then fixed it, you will still get the old, cached result in a browser like Firefox. Do your testing with curl --include http://www.example.com.

If you still get the same problem with curl, the problem is quite likely in the bit that you replaced with www.example.com. If those two strings aren't exactly the same, you will get a redirect loop.

It may also be worthwhile using 302 redirects until you are sure they are correct and only then switching to 301s.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.