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.

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

.htaccess:

RewriteCond %{HTTP_HOST} ^www\.domain\.com [NC]
RewriteRule ^(.*) http://domain.com/$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 www.mydomain.com to mydomain.com 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 www.mydomain.com, 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: mydomain.com instead of www.mydomain.com 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 mydomain.com/index.html 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" www.modularweb.net/en/portfolio/piecemaker2 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
show 2 more comments

1 Answer

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]
</IfModule>
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 mydomain.com –  Digital site Oct 26 '12 at 20:53
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.