How to Redirect Domain A to Domain B Using Only DNS A-Records and CNAMEs


2 views

When you need to redirect DomainA.com to DomainB.com but only have DNS-level access (A-records and CNAMEs), traditional HTTP redirects (301/302) aren't available. This limitation often occurs when:

  • Your registrar/host doesn't provide URL forwarding
  • You lack server configuration access
  • You need to implement wildcard redirects (*.DomainA.com)

Your existing setup shows:

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.

The critical missing piece is the root DomainA.com record - you only have CNAME for www subdomain.

To achieve full redirection (both root domain and subdomains):

; Root domain - use A-record to point to DomainB's IP
DomainA.com.    3600    IN    A         [DomainB's_IP_Address]

; www subdomain - CNAME already correct
www             3600    IN    CNAME     www.DomainB.com.

; Wildcard subdomains
*               3600    IN    CNAME     DomainB.com.

1. Root domain limitations: RFC 1912 specifies that CNAME records shouldn't exist alongside other records for the same name. Use A-records for root domains.

2. DNS propagation times: Changes may take 24-48 hours to fully propagate.

3. SSL certificates: This method won't handle HTTPS redirection automatically. Consider these options:

; Alternative for HTTPS support
DomainA.com.    3600    IN    A         104.18.22.45  ; Cloudflare IP

Use these commands to verify:

dig DomainA.com +short
dig www.DomainA.com +short
dig random.DomainA.com +short  ; Tests wildcard

If you need actual HTTP redirects (status codes 301/302), consider:

  • Using a free redirect service (Cloudflare, Netlify)
  • Setting up a minimal server just for redirects

Example minimal Node.js redirect server:

const http = require('http');
http.createServer((req, res) => {
  res.writeHead(301, {Location: 'https://DomainB.com' + req.url});
  res.end();
}).listen(80);

When you need to redirect DomainA.com to DomainB.com without access to server-side 301 redirects, DNS records become your primary tool. However, there are fundamental limitations:

// DNS records can point domains to IPs (A-records) 
// or alias one name to another (CNAME)
// BUT they cannot perform HTTP redirects

Your existing setup shows partial implementation:

www             3600    IN    CNAME     www.DomainB.com.

This correctly aliases www.DomainA.com to www.DomainB.com, but doesn't handle:

  • Naked domain (DomainA.com)
  • Subdomains (*.DomainA.com)

For full redirection capability through DNS only:

1. For the Naked Domain (DomainA.com)

Create an A-record pointing to DomainB.com's IP:

DomainA.com.    3600    IN    A         [DomainB's_IP_Address]
@              3600    IN    A         [DomainB's_IP_Address]

2. For Wildcard Subdomains (*.DomainA.com)

*.DomainA.com.  3600    IN    CNAME     DomainB.com.

3. For Specific Subdomains

blog.DomainA.com. 3600 IN    CNAME     blog.DomainB.com.
api.DomainA.com.  3600 IN    CNAME     api.DomainB.com.

1. IP Address Dependency: The A-record solution requires DomainB.com to have a static IP

2. HTTPS Issues: Browser may show certificate warnings for DomainA.com

3. Destination Control: You can't control the specific page users land on

$ORIGIN DomainA.com.
@              3600    IN    A         203.0.113.5
www           3600    IN    CNAME     www.DomainB.com.
*             3600    IN    CNAME     DomainB.com.
mail          3600    IN    CNAME     mail.DomainB.com.

This configuration will:

  • Send DomainA.com visitors to DomainB.com's IP (via A-record)
  • Route all subdomains to their counterparts on DomainB
  • Handle special cases like mail servers separately