HostArmada Web Hosting Knowledge Base

Knowledge is power! Use that power and achieve total and unconditional control over the Web Hosting Services!

How can I disable sub-domain access for my addon domains in cPanel?

The "Addon Domains" feature in the cPanel is excellent as it allows you to host multiple domains under your cPanel account. Even though an addon domain can be considered as an entirely independent domain name allowing you to deploy a site, it functions a bit differently than your primary domain name, in terms of the way Apache adds it inside its configuration file. Apache will create a vhost for the domain name, however, as a sub-domain of the primary domain name. For instance, if your primary domain name is domain.com and you add example.com as an addon domain, Apache will create a vhost for example.domain.com. To acquire the status of a fully-qualified domain name, Apache will then make example.com an alias for the example.domain.com, ultimately allowing people to view the content of the sub-domain while typing the actual domain in their browser.

Unfortunately, the sub-domain is very likely to be accessible along with the domain you added as an addon, which may cause Google to index the content twice under separate URLs, harming the rankings on your site.

To avoid this, you can take two approaches. In this article, we will be reviewing both of them, and you can decide which is best in your case:

.htaccess method

This method revolves around adding rewrite rule, which will display a 404 not found error when the sub-domain is visited. To take advantage of this method, you need to add the following snippet of code in your .htaccess file:

RewriteEngine On
RewriteCond %{HTTP_HOST} addon.primarydomain.com$

RewriteRule ^(.*)$ "https://youraddondomain.com/404" [R=301,L]

Please replace "addon.primarydomain.com" with the sub-domain that was created when you added your domain name as an addon and change "youraddondomain.com" with your actual addon domain.

The A record change method

As opposed to the above method, you can change the A record corresponding to the sub-domain your addon domain created and point it to a non-existing IP or to 127.0.0.1 (localhost), which will make the sub-domain resolve to the respective IP, making it inaccessible. If you are not sure how to edit the A record, you should definitely check out our tutorial on the matter.

Was this article useful and on point?

Find out more about HostArmada entire range of optimized Web Hosting Services and take action today on improving your website Loading Speed, Security, and overall Stability!