Reputation: 4459
I am having an issue with one of my sites where I need to redirect all subdomains to the main domain name. I have a Drupal site set up that shares content between 2 domains (using the Domain module). Here is basically what is going on.
In my .htaccess file I have these rules..
RewriteCond %{HTTP_HOST} !^mydomain\.com$ [NC]
RewriteRule ^(.*)$ http://mydomain.com/$1 [L,R=301]
This redirects any subdomain to mydomain.com, which is great!
The problem is that I have another domain (myotherdomain.com) which uses the same Drupal site to share content with via the Domain module.
With that .htaccess rule in place when I go to myotherdomain.com
it is redirecting to mydomain.com
which I do not want to happen. Is there any way that I can stop that from happening?
To recap:
Upvotes: 0
Views: 247
Reputation: 2083
Any RewriteCond before a RewriteRule will be applied. Have you tried adding simply RewriteCond %{HTTP_HOST} !^myotherdomain\.com$ [NC]
?
Upvotes: 1
Reputation: 143886
Just add another exclusion condition for your other domain:
RewriteCond %{HTTP_HOST} !^myotherdomain\.com$ [NC]
RewriteCond %{HTTP_HOST} !^mydomain\.com$ [NC]
RewriteRule ^(.*)$ http://mydomain.com/$1 [L,R=301]
This way, any request for "myotherdomain.com" won't get redirect, and any request for "mydomain.com" won't get redirected.
Upvotes: 0