Explanation about Addon Domain and using Modrewrite on it
By Reaper-X on Oct 11, 2006 in Apache, Guide, Internet, Linux, Tutorials, Web Servers
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
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!
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 ?
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 as a side note, 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 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 :)

Website RSS Feed
Stumble this post
Bookmark this post on Del.icio.us
Submit this post to Digg
Submit this post to Reddit
Print this
Trackback URL


Facebook
Last.fm
Twitter
YouTube









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.
Thanks for the article! Extremely helpful! The question is - how "friendly" is this code for search engine ranking?
Thanks!
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...
Very good advice! It actually works!
Thanks!
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!