Reaper-X » Guide » Internet » Linux » Tutorials » Web Servers » Explanation about Addon Domain and using Modrewrite on it

Explanation about Addon Domain and using Modrewrite on it

Okay, so you just bought a new domain name but you doesn’t want to buy another webhosting plan because your current webhosting already allow 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 to 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 usefull 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 ;)

Tags: ApacheDomainGuidehtaccessLinuxmodrewritemod_rewriteserversubdomainwebhostingyahoo

Leave a Comment

  1. мобильный сканнер said Jan 26, 2010 at 10:34 am

    Интересно, я даже и недумала об этом…

  2. Reaper-X said Sep 21, 2009 at 9:29 am

    Atul if you could give me a detailed explanation on what you did and what the error message is, perhaps i can help you :)

  3. Atul said Sep 20, 2009 at 3:37 am

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

  4. Levaquin Side Effects said Feb 7, 2009 at 7:23 pm

    Hi again,
    I have a domain at wiki.site.com. How can I implement this htaccess, so that every variation, including http://www.wiki.site.com, goes to
    wiki.site.com

    Thanks! Please email me!

  5. Levaquin said Jan 18, 2009 at 9:13 pm

    Very good advice! It actually works!

    Thanks!

  6. Magpie said 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…

  7. Gabi Bucataru said 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!

  8. Chris Palmeri said 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

CommentLeave a response

Please read our comment policy | XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>