Web Hosting Geeks | Web Hosting Experts
Need help? Call us 1(866)TOP-HOST

14120 reviews 1680 hosting providers

Questions & Answers

redirect subdomains to a new domain

Apr 13, 2012 by SaraSX
hi all

I want to change all my  subdomain to another main domain, I have about 50 subdomains on this domain and I need to shift them all to a new domaion
exp : subdomain1.domain1.com  would be  subdomain1.domain2.com

I need some advice as in how to get this done the easiest and most convenient way. If there is an automatic way, that would be just great.
Appreciate your help.

Note: I’m running cPanel on Centos

3 Answers

0 votes
Apr 13, 2012 by mike231
You can't do it completely automatically, you can't avoid creating the subdomains at the new domain because they should all have appropriate CNAME records in the new domain DNS and root folders on the server.
0 votes
Apr 13, 2012 by WebGuru
Hi there
you can do it using .htaccess and regex.
you should make a backup of your existing .htaccess file before adding the lines to it.
add the following .htaccess rule in the .htaccess file in the folder of each subdomain that you want to redirect

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.*)\.domain1\.com$ [NC]
RewriteRule ^(.*)$ http://%1.domain2.com [R=301,L]


place all of your subdomain folders in one directory, to simplify the process. then you can redirect them all with a single .htaccess file placed in the parent directory. If you choose this bulk option you have to be extra careful, because there are cases when these rules could intefere with existing rules of your main domain.

hope this helps
0 votes
Apr 13, 2012 by randy999
from WHM.

    Go to Account Functions.
    Click Modify An Account.
    Select the domain and click Modify.
    Change the domain and click Save.

you would have to do this for every domain. It shouldn't take too long.