How to map subdomain to a domain with CNAME?

2.2k views Asked by At

I would like to point CNAME records for www.example.com to sub.example2.com. The hosting for example2.com is a shared hosting (cPanel without Addon domain feature).

So, what I did was to add a subdomain in the cPanel: sub.example2.com

I then added a CNAME record for www (and without www) of example.com to sub.example2.com

After propagation, www.example.com shows the default server page of the hosting instead of showing the sub domain contents. If I access this subdomain directly, it works fine.

Can somebody help me with these, please? Thanks.

2

There are 2 answers

0
Josip Rodin On BEST ANSWER

If I understood your intent correctly, you have to tell cPanel that you want to serve www.example.com, not the other thing. Either that, or create a third virtual host somewhere (anywhere) that would handle www.example.com by doing a HTTP redirect to sub.example2.com.

Note also that you can't have a CNAME record for example.com without www, because a domain record already has SOA and NS records, and CNAME can't be combined with anything else - it has to be an A record.

2
Leo On

Another thing to know about what you're doing:

You can't use a CNAME in the zone apex

(so as in the example.com zone a record "@ IN CNAME example2.com")

Theoretically it is, but in reality too many (resolving) nameservers get confused.