Explanation about Addon Domain and using Mod_rewrite on it

Reaper-X | Oct, 11 2006 Comment10 Comments RelatedRelated Posts Bookmark and ShareShare RSS SubscribeRSS Feed

Okay, so you just bought a new domain name but you don’t want to buy another webhosting plan because your current webhosting allowed you to host multiple domain under one account so you decided not to buy another hosting. Although addon domain can be set up easily, but as you already knew that addon domain can be accessed through various url because addon domain is a subdirectory of your current hosting directory unless of course you have full control of your server and put that directory somewhere else and map your webserver to that directory ;)

For example you already have a website hosted by some webhosting service using mydomain.com as your domain name, most likely your public_html or your web root directory will be /home/yourdomain.com/public_html. And if you buy another domain name (for example addondomain.com), your addon domain web root or public_html directory will be /home/yourdomain.com/public_html/addondomain (although the addon domain name directory may vary because you can change it)

And to access your addon domain name or url, you can use various method like below :

www.mydomain.com/addondomain
mydomain.com/addondomain
addondomain.mydomain.com
www.addondomain.mydomain.com
www.addondomain.com
addondomain.com

The first url, sure doesn’t looks good. Because everyone can see that your addondomain is a subdirectory of your primary domain. As for the second url, it’s not that good too. Because most of web surfer always forgot to add www before going to a website (although it’s up to you whether you want your website with or without www) .. but if it’s for me i’d rather have www by enforcing them automatically like Yahoo!, Google or many other major web sites out there

The third and fourth url is because is not good too because it list your addondomain as a subdomain of your primary domain, and i’m pretty sure no one like that, right? but i could be wrong of course :D

And the fifth and sixth address is the correct url, but the sixth address is without www before your domain name. And just like i said before, that depend on you .. but in this post, i’m going to tell you how to force your website to always using www in front of your addondomain or domain name and if they write the url using the first – fourth address, it’ll automatically change into www.addondomain.com

And in order to use that, you’ll need modrewrite enabled on your Linux Webhosting (and of course your Linux Server must be running Apache as the web server)

Here’s a few lines of code you should put into your .htaccess file so it’ll automatically do the job for your addondomain, no matter what url typed into the address bar of your visitors browser

<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?addondomain\.mydomain\.com [NC,OR]
RewriteCond %{HTTP_HOST} ^!www\.addondomain\.com [NC]
RewriteRule ^(.*)$ http://www.addondomain.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^addondomain.com [NC]
RewriteRule ^(.*)$ http://www.addondomain.com/$1 [R=301,L]
RewriteCond %{REQUEST_URI} ^/addondomain($|/.*$)
RewriteRule ^.* http://www.addondomain.com%1 [R=301,L]
</IfModule>

The IfModule used just in case your server didn’t have modrewrite enabled, so your server doesn’t return a 500 status header, as for the other part, i think it self explained because you can see it clearly … as a side note, i’m using this on a few of my domain name. And hopefully this small .htaccess or modrewrite guide / tips / whatever can be useful for you :)

In case you’re wondering what kind of redirect i’m using here, and that is a Permanent Redirect knows as 301 Redirect, that is basically telling the search engine to always pull content from your www.addondomain.com and obiously also pass the pagerank that is placed before on addondomain.com (without www), or any other means to access your addondomain to www.addondomain.com because it’s a permanent redirect unlike the temporary redirect known as 302 redirect ;)

Bookmark and Share

Leave a comment

Comments

  1. Nick Jul 14, 2010 at 11:34 AM

    this was an amazing article and saved me a lot of time! thank you very much. what i would like to know now is how do i set it up for multiple domains? i.e. it works for redirecting one domain to a certain subdirectory, but how do i go about adding another one to another subdirectory? hope that makes sense!

  2. Biro Jasa birojasa.pengunjungsetia.com May 30, 2010 at 12:27 AM

    thank you, my problem get done quickly because of this great tutorial. Bravo Reaper-x

  3. Saku Apr 21, 2010 at 1:42 PM

    Hi,
    What about when my subdomain is in a different root than the main domain: eg in my case maindomain.fi subdomain.us – what should I write now?
    Saku

    • Reaper-XReaper-X Apr 21, 2010 at 6:49 PM

      I’m not quite sure about your question, did you mean addon domain? because subdomain is not the same as addon domain :)

      Anyway, if you’re asking about addon domain placed in another Document Root, then there’s no need to write anything for your second domain, because it’s not located in the same directory as your maindomain. The only thing you should care about is forcing www or not using www at all on your addon domain (for SEO purpose)

  4. Reaper-XReaper-X Sep 21, 2009 at 9:29 AM

    Atul if you could give me a detailed explanation on what you’ve done so far, perhaps i can help you :)

  5. Atul oceanofweb.com Sep 20, 2009 at 3:37 AM

    not wrking for me…wasted whole 1 day..pls do mail me the solution

  6. Levaquin fqhelp.com Jan 18, 2009 at 9:13 PM

    Very good advice! It actually works!

    Thanks!

  7. Magpie alternativeanswers.net Jul 16, 2008 at 8:28 PM

    What can I say??? THANK YOU! You are a HERO!

    I have spent about 6 hours trawling the web for help with this and everyone seems to be writing ONLY about how to make SEO url’s from dynamic content…all I wanted was…EXACTLY what you have given me here…and it works beautifully! Thank you SOOO much! I only just found your site but im going to come here in future for troubleshooting! So, thanks again, and have a virtual pint on me…

  8. Gabi Bucataru gabtone.com Feb 29, 2008 at 1:36 AM

    Thanks for the article! Extremely helpful! The question is – how “friendly” is this code for search engine ranking?
    Thanks!

  9. Chris Palmeri smcknights.com Feb 23, 2008 at 7:09 AM

    This article is awesome. I have copied many different pieces of code today trying to make this happen. Not only does this one work but it covers all the possibilities. Extremely helpful.

Trackbacks/Pingbacks

  1. Force WWW on your Domain / URL - Reaper-X
  2. Addon Domains - Solving duplicate content issue using .htaccess
  3. mossism.net
  4. Between using Subdomain and Subdirectory by Reaper-X .:[ ID ]:.

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>