CPanel Addon Domain without Subdomain

It's a very common problem in shared web hosts, check it out and optimize your website by implementing it!

Most of the shared web hosts that allow hosting of multiple sites from a single hosting account (like Hostmonster, Hostgator etc.) has a common structure. You'll have one main website or domain and all the other websites or domains will be added as Addon domains from cpanel. This way you can host multiple websites from a single hosting account. However, this approach has a problem. With each Addon domain created from cpanel, you also automatically get a subdomain (almost in all cases). Now, the challenge is to using the Addon domain, without the auto created subdomain. This may be important for your website optimization.Since, most of the times, they enable this Addon domain option in cpanel, by creating a subdomain of the main site and then pointing that subdomain to the newly created Addon domain. So in a way, the Addon domain is joined together with the subdomain, and doesn't work without it.

Problem Description: For example, you have registered your account with the main site named www.main-domain.com in cpanel. Now you want to host another site, named www.another-domain.com, from the same hosting account. This can only be done using the Addon domain option if you are using cpanel. When you add this new domain with the Addon domain option, they will automatically create a subdomain of the main site (e.g. another-domain.main-domain.com). Now both the newly added domain (www.another-domain.com) and the subdomain (another-domain.main-domain.com) will actually point to the same location; thus the web site content is accessible from both the addresses.

Now, you may not want this for multiple reasons:

  1. You may not want other people to know that you run both the sites www.main-domain.com and www.another-domain.com and specially that you run www.another-domain.com as an Addon domain of www.main-domain.com.
  2. You don't want search engines to tag your site with two different addresses (www.another-domain.com and another-domain.main-domain.com), which may decrease your site's ranking for duplicate contents, divide your site's traffic and even worse - the subdomain (another-domain.main-domain.com) may get better ranking than the original site (www.another-domain.com).
  3. If you run Blog software like WordPress, your site will still be accessible from both the subdomain and the main domain, But the subdomain will send erroneous contents, which may carry a negative point to your site.
  4. There can be many other unforeseeable reasons, But the main point is: You don't want people to visit one of your site as a subdomain of another site.

Solution:

I use an htaccess solution that works both in Hostmonster and CirtexHosting; And it should work in any other hosting site that allows .htaccess with mod_rewrite capability.

So if you have the same problem, then just put a .htaccess file in the Addon domain directory with the following CODE:

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{HTTP_HOST} main-domain.com$
RewriteRule ^(.*)$ "http://www.another-domain.com/" [R=301,L]

</IfModule>

Note that, here, main-domain.com is the main site registered with your hosting account, and www.another-domain.com is the new domain you've added to the same shared hosting, using the Addon Domain option.

Of course, you may already have an existing .htaccess file. For example, a tipical WordPress installation will have a .htaccess file with the following CODE:

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

</IfModule>

In that case just modify the .htaccess file with the following code:

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{HTTP_HOST} main-domain.com$
RewriteRule ^(.*)$ "http://www.another-domain.com/" [R=301,L]

RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

</IfModule>

Now, with this new .htaccess file, your new Addon domain will essentially be visible from its original domain only. If anyone tries to access it with the subdomain, then he will be redirected to the main domain. So the browser will always show your main site's address, instead of the subdomain. Besides, with the new code in place, search engines will never tag your site with the subdomain. So most likely, no one will even try to access your site with the subdomain.

So, with this new .htaccess code, fell free to add as many Addon domains as you like, with just one hosting account.

If, Google is already showing your unwanted subdomains, then following this process will eventually remove them. Although if you want them to be removed quickly, then you'll have to create a webmaster account in Google, verify the subdomain as you own and request to remove it.


Update:

Also you might always want others to access your site as www.another-domain.com, instead of just another-domain.com. Since, to search engines, they are two different sites. So, it's always better to fix your site as either www.another-domain.com or another-domain.com.

So, now it's time to update the previous solution, to the one, that does both:

  1. Removes the subdomain access from your addon domain.
  2. Fixes your site to just one address: either to the one with www or to the one without www

Assuming that you'll use www.another-domain.com as your fixed site address, following will be the most optimized htaccess rewrite code to accomplish both the goals:

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{HTTP_HOST} !www.another-domain.com
RewriteRule ^(.*)$ "http://www.another-domain.com/" [R=301,L]

</IfModule>

Of course, just as before, for an existing WordPress installation (assuming you have default WordPress htaccess code), the code will look like:

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{HTTP_HOST} !www.another-domain.com
RewriteRule ^(.*)$ "http://www.another-domain.com/" [R=301,L]

RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Also, I'm not sure, but for some people (with multiple hosting from a single account), this Hostmonster KB article may also be helpful.

[This update is attributed to Mahbub vai, as he pointed out a similar solution in Hostmonster Knowledge base. Although code here is more optimized than that of Hostmonster Knowledge Base, still their code actually helped me thinking of a different approach; And from that different approach, I found this even better solution.]


Update-2:

Another blog post suggested a slightly different solution, which will allow to soft-link your addon domain with the main site's subdomain. That's a different solution, but not necessarily the correct one. Since, the main goal is to remove all sorts of soft-linking from the subdomain; and in essence, deny anyone to use your site from the subdomain. So the bottom line is: it is always better if you remove the ability to soft-link any of your perma-links (e.g. a perma-link to a blog post) from the sub domain and force your user to use your site  from its original site address.

72 thoughts on “CPanel Addon Domain without Subdomain”

  1. Thank you so much, I've been searching for this info at hostgator, but every has thier own solutions, including robot files. This solved my issue. Thanks for the informative post.

  2. another afterthought, does anyone know how to implement the add on domain option in cpanel, using htaccess for a hosting account that does not support cpanel? Tried framed redirects, but this still showed the original hosting domain.
    any help would be great on this one.

  3. Great article, very nicely done, you should also include using htaccess to rewrite a subdomain, as most people will want that. just a thought.
    cheers.

  4. Don't you think returning a 404 is much better than 301? If you return a 301 and the user gets redirected to the proper subdomain URL, atleast he would know that he got your mainsite URL correctly (because it was redirected, instead of getting an error). He can now concentrate attacking your mainsite domain since he knows all your subdomains are under it.

    1. That might work, however I've seen some site to implement the zone record such a way that without the subdomain, addon domain would not work.

      So if you just delete the zone record of the subdomain, most likely the addon domain will stop workin in those cases. The thing is, they don't add the subdomain as a convenience, rather it's a way for them to implement the addon domain.

      Also, not all the hosting company will let you edit the zone record. So I guess you're stuck with this kinds of implementation in most cases.

  5. Hi I have a .co.za domain and this solution keeps giving me an error of
    page not redirecting correctly, is there something im doing wrong?

    1. Hi Richy,

      I think .co.za has nothing to do with the error. Possibly you've implemented the CODE wrongly!

      Say your site name is http://www.domain.co.za, in that case place the following CODE on this site's root folder. Remember NOT on the main site's root, rather the addon-domain's root. Say your main site is YourSite.com and http://www.domain.co.za was added as an addon domain with domain.YourSite.com subdomain. In that case, the subdomain's folder is the root folder for your co.za addon domain.

      Now that you know where to put the CODE, put the following CODE in your .htaccess file (if it is not a wordpress installation):

      RewriteEngine On

      RewriteCond %{HTTP_HOST} !www.domain.co.za
      RewriteRule ^(.*)$ "http://www.domain.co.za/" [R=301,L]

      If it's a wordpress installation or if your site contains preexisting htaccess CODE, then remember to adjust it accordingly.

      If my suggestion still doesn't work, then I'll need to see how your site is implemented.

  6. Very Very helpful , thank you sir , it was very helpful , and i used it in my add-on domains . Actually i don't understand .htaccess much . but thanks you made it easy for me . bye ,, take care...

  7. Thanks Fayaz, i have only just started using add on domains rather than hosting each site individually and been looking for a solution for this as been worried about a potential google duplicate content penalty. Not using the hosting companies you mentioned but fingers crossed will work through cpanel with my host.

  8. I have been scouting around for this particular insight, thank you! What other sites can you think I should check out? Websites like this are difficult to come across, make sure to continue the great work.

Leave a Reply

Your email address will not be published. Required fields are marked *