0

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.

Digital site
  • 190
  • 1
  • 10
  • 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](http://serverfault.com/q/145777/126632). – Michael Hampton Oct 26 '12 at 20:52
  • @Digitalsite So you want to redirect the homepage to non-www, but leave all other resources alone? – Shane Madden Oct 26 '12 at 21:01
  • yes, correct. That's all I'm after – Digital site Oct 26 '12 at 21:08

1 Answers1

1
<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{HTTPS} !=on
  RewriteCond %{HTTP_HOST} ^www\.example\.com/$ [NC]
  RewriteRule ^ http://example\.com/ [R=301,L]
</IfModule>
  • 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