.htaccessmod-rewriteurl-rewritingapache2.2

Redirect all subdomains to a new root domain


I am looking to change a root domain of a site.

The domain in question has several sub domains as aliases.

I would like to use htaccess to redirect the sub domains to the new domain:

eg :

test.domain1.com > test.domain2.com

Looking around I can see that the condition I need is as follows :

RewriteCond %{HTTP_HOST} ^[^.]+\.domain\.com$ [NC]

But I cannot see what the RewriteRule should be.

Any help would be greatly appreciated.


Solution

  • To redirect test.subdomain.com to test.subdomain2.com you can use the following Rule :

    RewriteCond %{HTTP_HOST} ^([^.]+)\.domain1\.com$ [NC]
    RewriteRule ^ http://%1.domin2.com%{REQUEST_URI} [NE,L,R]