Search code examples
.htaccesshttp-redirecturl-rewritingsubdomaincname

Getting subdomain to redirect and follow CNAME


i have migrated a domain from olddomain.com to newdomain.com...i want all URLs to redirect from olddomain.com to newdomain.com. I got this part working. My issue now is that I have a CNAME on newdomain for help.newdomain.com -> externaldomain.com (uses referrerURL to land on proper page) I need to redirect help.olddomain.com -> help.newdomain.com -CNAME-> externaldomain.com Is this possible with .htaccess rewrite? if not, is there another way to skin it?


Solution

  • Yes, a 301 .htaccess rewrite should do it. Put this in the server that currently serves help.olddomain.com:

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

    If you really want it to hit help.newdomain.com first, use that in the RewriteRule instead.