w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
apply subdomain mapping to an addon domain in Hostgator

It is most likely that your test.bar.com subdomain is unknown to the world-wide DNS system. For it to know, you will have to register it with the DNS system. (If this is just for your private use and not public, you can use your systems /etc/hosts file to map the name to the server ip)

I assume Hostgator is the Domain Name Registrar for both foo.com (primary domain) and bar.com (addon domain) and you have access rights to the Domain control panels (CPanel/Plesk/etc.) to do the required.

When you bought an addon domain (bar.com) for your primary domain (foo.com), Hostgator would have setup a DNS CNAME (Canonical Name Record) record for www.bar.com pointing to the same Host record (also called A record/Address record) of your primary domain, so that both domains share the same hosting. So you now have to do the same thing for test.bar.com subdomain. You can find a short guide here from Hostgator: How to change DNS zones (MX, CNAME, and A records).
Note: Changes to DNS records may need a few hours to take effect.

This would be annoying for you to set them up manually each time you want a new subdomain. Many Domain name registrars (including Hostgator) also support a feature called WildCard domains. They allow you to use * (wildcard) for the CNAME record pointing to your primary domain. This makes whatever.bar.com, point to the same address www.bar.com is pointing.

To support individual sites for your primary, addon domains and their subdomains, Apache uses domain name-based virtual hosts. If you want to load the same site for whatever.bar.com as www.bar.com, Apache allows * wildcard in ServerAlias directive. Make sure *.bar.com as a ServerAlias is setup in www.bar.com VirtualHost configuration. Otherwise, you have to setup separate VirtualHost configurations for each subdomain.
Note: There is also a VirtualDocumentRoot apache directive that can be used to provide separate document roots depending on the domain name.





© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.