Webmasters Stack Exchange is a question and answer site for pro webmasters. Join them; it only takes a minute:

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 have the following which redirects mydomain1.co.uk and mydomain1.com to www.mydomain1.com perfectly.

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

I am trying to add an additional rule for a second domain, that will redirect all non www traffic for mydomain2.com to www.mydomain2.com.


share|improve this question

migrated from stackoverflow.com Jul 8 '11 at 11:16

This question came from our site for professional and enthusiast programmers.

You seems to have quite a few domains and subdomains pointing to the same folder (so they share the same .htaccess) which makes your original approach not suitable for such situation. Use these rules instead of yours:

RewriteCond %{HTTP_HOST} =mydomain1.co.uk [OR]
RewriteCond %{HTTP_HOST} =mydomain1.com
RewriteRule ^(.*)$ http://www.mydomain1.com/$1 [R=301,L]

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

These rules will only work with domains/subdomains described in your question and will not catch any other subdomains (e.g. hello.mydomain1.com will not trigger these rules).

share|improve this answer
+1 you are more of a htaccess Jedi then I – John Conde Jul 8 '11 at 14:31

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.