Running Two Domains On One Shared Hosting Server
Most people run their web sites on one of the many inexpensive shared hosting servers running a LAMP environment. If you are like me, you probably have a number of domain names registered, perhaps all parked on the same server pointing to the same site. It would be great to split things up, though, to point one domain to a particular site on your server, and other domains to their own site. Apache lets you do this using a special .htaccess file, which configures the server software on the fly. You can set up unique sites in their own directory on your server, and then
direct Apache to point requests for a particular domain to that folder. Let’s assume the domain you want to redirect is called “somedomain.com”, and the folder on your server where the site files reside is called “somedomain”. Create a plain text file with a text editor and add the following to it:
RewriteEngine On
Options +FollowSymlinks
RewriteBase /
RewriteCond %{HTTP_HOST} somedomain.com
RewriteCond %{REQUEST_URI} !somedomain/
RewriteRule ^(.*)$ somedomain/$1 [L]
If you are on a Mac or Linux machine, you will need to save the file as something like htaccess.txt so the operating system does not hide the file (.htaccess is a special name the operating system recognizes, and will try to interpret the commands within). Upload the file to the root directory on your server (sometimes called, htdocs, public_html, or www among other names). Rename it .htaccess, then try accessing somedomain.com in a browser. It should direct your request to the files within the somedomain folder transparently, giving the effect of multiple domains with their own site running on the same shared hosting environment.





Hi Aarron, (Chris here again)
Just wanted to ask a question about this method. Would this work with multiple domain name on the same server? For example, let’s say I added
RewriteEngine On
Options +FollowSymlinks
RewriteBase /
RewriteCond %{HTTP_HOST} mydomain.com
RewriteCond %{REQUEST_URI} !mydomain/
RewriteRule ^(.*)$ mydomain/$1 [L]
RewriteEngine On
Options +FollowSymlinks
RewriteBase /
RewriteCond %{HTTP_HOST} anotherdomainihave.net
RewriteCond %{REQUEST_URI} !sanotherdomainihave/
RewriteRule ^(.*)$ anotherdomainihave/$1 [L]
RewriteEngine On
Options +FollowSymlinks
RewriteBase /
RewriteCond %{HTTP_HOST} a3rddomainihave.org
RewriteCond %{REQUEST_URI} !a3rddomainihave/
RewriteRule ^(.*)$ a3rddomainihave/$1 [L]
to my .htaccess file. Would this work or is it only for two?
Thanks
May 11th, 2007 at 4:59 pmYou have the general idea here, but you should be able to abbreviate it as follows:
RewriteEngine On
Options +FollowSymlinks
RewriteBase /
RewriteCond %{HTTP_HOST} mydomain.com
RewriteCond %{REQUEST_URI} !mydomain/
RewriteRule ^(.*)$ mydomain/$1 [L]
RewriteCond %{HTTP_HOST} anotherdomainihave.net
RewriteCond %{REQUEST_URI} !sanotherdomainihave/
RewriteRule ^(.*)$ anotherdomainihave/$1 [L]
RewriteCond %{HTTP_HOST} a3rddomainihave.org
May 11th, 2007 at 5:11 pmRewriteCond %{REQUEST_URI} !a3rddomainihave/
RewriteRule ^(.*)$ a3rddomainihave/$1 [L]
I used your method before and it worked. But I’m trying it again after reseting my servers and it’s not working.
February 10th, 2008 at 12:51 am