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:
- 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.
- 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).
- 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.
- 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 OnRewriteCond %{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 OnRewriteBase /
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 OnRewriteCond %{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.
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:
- Removes the subdomain access from your addon domain.
- 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 OnRewriteCond %{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 OnRewriteCond %{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.]
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.
Really useful article. I have just used the code and paste it into .htaccess under public_html/quotesgalaxy.in . It works. Thank you so much.
Hi! This might be a bit off topic but it concerns addon domains. I hope you can help me with this problem.
I created an addon (myaddon.com) domain in my main (mymain.com) domain. And following your instructions I'm able to avoid the duplicate subdomain problem. Entering the addon domain in the address bar works perfectly.
My problem is when I search my website, in the search results it displays mymain.com instead of myaddon.com.
That is most likely your search implementation related problem. However, it's difficult to comment without further data.
For example:
1. What are the actual web site addresses? Addon & main?
2. How did you implement the search functionality?
Hi my name is harry and can you help me http://www.another-domian.main-domain.com/ to redirect http://www.another-domian.com via CP and but How to solve http://www.main-domain.com/another-domian.com to http://www.another-domian.com
You can do that using a .htaccess file in the /another-domain.com directory of http://www.main-domain.com/
in that .htaccess, use the same CODE as described above, it'll work:
RewriteCond %{HTTP_HOST} !www.another-domain.com
RewriteRule ^(.*)$ "http://www.another-domain.com/" [R=301,L]
Great post.
I've had a nightmare trying to solve the following problems.
1. I've registered a domain with Company A (ex: http://www.domainA.com)
2. My hosting is with Company B. To be able to use hosting for domainA.com I registered a subdomain (ex: sub.companyB.com) and installed WordPress on it.
3. I set-up the DNS to point to CompanyB.
However, this created a problem. When you go to http://www.domainA.com and begin to click on the website the subdomain files continue to show in the web address under sub domain names (ex. sub.companyB.com/about). I don't want that. I want all files to be organic from domanA.com (ex: http://www.domainA.com/about)
-------------
SOLUTION:
After a lot of frustrations I figured out how to go about to remove this problem if the domain is registered with a different company than the hosting provider (even my hosting provider could not provide an answer to help me resolve this issue):
1. In your hosting account register an addon domain under your real domain name (which may be parked with another company than the hosting company)
ex (addon): http://www.DomainA.com
2. Login to your account where you purchased the domain. Edit the DNS entry to reflect your hosting provide.
2. Now go back to your hosting CPanel and go to "Wordpress".
3. Install WordPress on your addon domain http://www.domainA.com
4-a. If you already have a previous subdomain, export the full content within the WordPress admin menu as an xml file. Upload it into your new wordpress site domainA.com (which should have login: domainA.com/wp-admin)
4-b. If you don't have a previous subdomain, you can now login to your wordpress and begin to create your website.
6. Now you should have all traffic to your organic website, connected to your domain.
If the content is completed in the organic website you can delete and uninstall your subdomain.
Hi, thanks for the long comment. Yes, that is the standard procedure.
Excellent Idea, I used on my siteground hosting. The only problem as Faiz told you, is what about subfolders or files?
It can be modified to work with subfolders or files.
However, that was not my intention.
Please look into update-2 at the end of the post. I've linked to another solution that does just that and I also explained why that may not be a good idea.
But it is not working if I click on anyone of the menu item.
all menu again starts to show ie. maindomain.com/addondomain.com/contact-us/
Thanks man
This works great!
anything for you 😉
Dear, this solve the problem
From : http://www.another-domian.main-domain.com/
To : http://www.another-domain.com/
but did not solve the problem
Form : http://www.another-domian.main-domain.com/ somelinks.html
To : http://www.another-domain.com/somelinks.html
as on my website i have 100s of such kinds of pages and links?
Hello
I am new to the hosting business, and I am struggling for days now with a similar issue
I purchased an account from godaddy and registered a new domain which is working ok.
my account plan allow addon domains and wanted to make three other sites in addition to my primary site. so I add a new addon domain and installed WP on it. but when I try to load it from my browser I get "server not found" and if look it up using whois my addon domain is there and registered correctly with godaddy.
what shall I do to get it to load correctly.
I searched for .htaccess file in the root and public_html directories and found none
I highly appreciate any help
nice article..
when you create an addon domain, many hosting services like hostgator makes your addon domain accessible through-
1. addon-domain.com
2. addon-domain.main-domain.com
3.main-domain.com/addon-domain
Is the solution given above works for the third case also..?..I think it is also going to be bad for seo. If not, please provide the suitable solution.
thanks in advance.
we can also redirect our automatic created sub-domains. But i don't know weather it is good or bad for seo pointy of view.
It worked like a wonder! Thanksss 🙂
I have main domain pakmotors.net with HG. I have made an addon domain in HG like (pakmeet.net) on my main domain. When I load site script, it is working / being loaded with subdomain name i.e (pakmeet.pakmotors.net) but when I put just the addon domain (pakmeet.net), it is not working. Can somebody help me.
Looks like you figured it out.
Wow...it works flawlessly. Big Thanks