Domain – How to redirect domain A to domain B using A-Records and CNAME records only

a-recordcname-recorddomaindomain-name-systemhosting

I have 2 domains hosted with different hosts. I need to redirect Domain A to Domain B. Unfortunately I can't do a 301 redirect from Host A, but can only modify/add DNS entries (A-Records and CNAMEs) at Host A.

Surely it is possible to redirect www.DomainA.com to www.DomainB.com using only A-records and CNAMEs?

At present, the DNS entries are:

DomainA.com.    3600    IN    SOA       ns1.HostA.net.
www             3600    IN    CNAME     www.DomainB.com.    
DomainA.com.    3600    IN    NS        ns1.HostA.net.  
DomainA.com.    3600    IN    NS        ns2.HostA.net.  
DomainA.com.    3600    IN    NS        ns3.HostA.net.

I want to redirect

DomainA.com -> DomainB.com
*.DomainA.com -> *.DomainB.com

I've tried the suggestion from this other post but it didn't work.

How can I achieve this only with A-Records and CNAMEs please? Thank you for your advice.

Prembo.

Best Answer

So you are not looking at redirection as such (as that happens at the app level, i.e. on Apache/Nginx/wherever) but rather on the DNS resolution. The host on which DomainA is hosted will or should never be hit, based on your description as you want the DNS requests to be resolved to the IPs of DomainB. Unless I'm missing something in your request?

As Shane pointed out DNS is not capable of HTTP redirection - that's an application/webserver duty. You could make DomainA and DomainB resolve to the same IP on DNS and all would work. But if you're looking to do this on per URL/per-path way then this is not possible - DNS is not capable of that - it's a simple DNS->IP service, what's happening with the actual URL is the webserver's task.

After the comment below, what I'd do is to refer all DNS records for DomainA to the same IP(s) as DomainB is pointed to - this way you will get HTTP request hitting hostB and then it's just a simple matter of:

  1. creating a particular Apache Name Baseed Virtual host - which will be serving files from its own DocumentRoot
  2. creating permanent redirect on Apache like this:

This will rewrite anything coming to DomainB to DomainA which can be hosted on the same server or somewhere else. I appreciate that the second option is probably an overhead and not necessary if you can/are allowed to create Name Based Virtual hosts on apache.

<VirtualHost *:80>
  ServerName DomainB
  Redirect permanent / http://DomainA/
</VirtualHost>

I'd go with 1. - point all DNS records of DomainA to the same IP(s) as DomainB is pointing and create particular Name Based VirtualHosts on Apache.