0
RewriteCond %{SERVER_NAME} ^([^.]+\.[^.]+)$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]

I want to rewrite mysite.com to www.mysite.com when no subdomain is indicated. If for example someone requests test.mysite.com then it will remain test.mysite.com, but mysite.com alone will be redirected to www.mysite.com.

Just wanted to make sure that what I have now is right and there are no possible problems in the condition and rule that I'm using. Solution above was recommended by one of the fellow SO users, but I replaced {HTTP_HOST} with {SERVER_NAME}

DavidW
  • 5,069
  • 14
  • 46
  • 68

1 Answers1

0

it should do the trick, if you do not have multi subdomain like test.test.mysite.com

Anywho, regarding the HTTP_HOST vs SERVRE_NAME, check HTTP_HOST vs. SERVER_NAME

Community
  • 1
  • 1
Jean-Christophe Meillaud
  • 1,961
  • 1
  • 21
  • 27