Reputation: 1155
Normally if I wanted to redirect a domain and all pages in that domain to another new domain, I'd use this in my .htaccess file:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !example.com$ [NC]
RewriteRule ^(.*)$ http://new-example.com/$1 [L,R=301]
But I have an account with a host that uses cpanel and sets up addon and subdomains to be included in the web root of the account's primary domain, instead of outside. Unfortunately this htaccess code then affects all of those other domains too. How can I write this so that it only affects example.com and not the other addon domains of the account, but STILL redirect all files in the primary domain?
Upvotes: 1
Views: 284
Reputation: 785246
Replace your existing rule with this:
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule ^ http://new-example.com/%{REQUEST_URI} [L,R=301]
Upvotes: 2
Reputation: 7880
You have to declare which domains you want to redirect. Before you were saying all domains that were not example.com were redirected to new-example.com.
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?example1\.com$ [OR]
RewriteCond %{HTTP_HOST} ^(www\.)?example2\.com$ [OR]
RewriteCond %{HTTP_HOST} ^(www\.)?example3\.com$
RewriteRule ^(.*)$ http://new-example.com/$1 [L,R=301]
Upvotes: 1