Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I was trying to force my domain to redirect without www and could success through this code:


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

however, this code is going to redirect all www to non-www, which is not what I want. I just want to make the main domain from to and the rest of the urls should be forced to www.

any idea how to add or modify the code so I can achieve that through .htaccess ?

Update: Thanks to all. I found out that swf file from piecemaker was corrupted and updated it with new one. so now it is all fine and works on both www and non-www. I'm still curious how to solve this issue anyways using .htaccess. Thanks again.

share|improve this question
What do you mean by "main domain"? Please provide more clear examples. What do you want to have without a www, and what is it now? What do you want to have with a www, and what is it now? – Shane Madden Oct 26 '12 at 20:35
I mean the domain itself, I have a swf file that doesn't work on www, but without it so I want to have the main page of my domain to become like this: instead of however, the code I used above force all urls on my domain to get redirected without www. now I'm still using that code above, but trying to find a way how to make it force only and that's it. The rest of urls should contain www. I hope it is clear now – Digital site Oct 26 '12 at 20:44
What's wrong with ditching the superfluous "www" on all URLs? – Chris S Oct 26 '12 at 20:47
as I know, it is not recommended for SEO. everywhere I look around for such issue, a warning message states that it is not recommended to avoid using www. It is just I have an issue with swf "peicemaker 2" not working with www, but without it – Digital site Oct 26 '12 at 20:52
@ChrisS Plenty. – Michael Hampton Oct 26 '12 at 20:52
up vote 1 down vote accepted
<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{HTTPS} !=on
  RewriteCond %{HTTP_HOST} ^www\.example\.com/$ [NC]
  RewriteRule ^ http://example\.com/ [R=301,L]
share|improve this answer
Thanks for the code, but this one does what the code above does; same job. it forces all urls to be redirected without www, but I want only – Digital site Oct 26 '12 at 20:53

Your Answer


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.