Mobile app version of vmapp.org
Login or Join
Phylliss660

: Htaccess and 301 redirects - multiple domains I have the following which redirects mydomain1.co.uk and mydomain1.com to www.mydomain1.com perfectly. RewriteCond %{HTTP_HOST} !^(.*).mydomain1.com$ [NC]

@Phylliss660

Posted in: #301Redirect #Htaccess #ModRewrite #MultipleDomains

I have the following which redirects mydomain1.co.uk and mydomain1.com to mydomain1.com perfectly.

RewriteCond %{HTTP_HOST} !^(.*).mydomain1.com$ [NC]
RewriteRule ^(.*)$ www.mydomain1.com/ [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 mydomain2.com.
Thanks!

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Phylliss660

1 Comments

Sorted by latest first Latest Oldest Best

 

@Gloria169

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 ^(.*)$ www.mydomain1.com/ [R=301,L]

RewriteCond %{HTTP_HOST} =mydomain2.com
RewriteRule ^(.*)$ www.mydomain2.com/ [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).

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme