Skip to content


Multiple Domains in one root

This section contains the codes and tips to improve the ranking of your site into the search engines. It will also contain info regarding the Mod Rewrite technique.

Multiple Domains in one root

Postby Web Guru » March 25th, 2008, 9:54 am

If you are in the unfortunate position of having your sites living on a host that doesn't support multiple domains, you may be forced to roll your own with .htaccess and mod_rewrite. So long as your physical directory structure is well thought-out, this is fairly simple to achieve.

For example, let's say we have two domains, pointing at a single hosted root; domain-one.com and domain-two.com. In our web server root, we simply create a folder for each domain, perhaps one/, and two/ then in our main (root) .htaccess, rewrite all incoming requests, like this..

All requests NOT already rewritten into these folders, transparently rewrite..
Code: Select all
    #two domains served from one root..
    RewriteCond %{HTTP_HOST} domain-one.com
    RewriteCond %{REQUEST_URI} !^/one
    RewriteRule ^(.*)$ one/$1 [L]

    RewriteCond %{HTTP_HOST} domain-two.com
    RewriteCond %{REQUEST_URI} !^two
    RewriteRule ^(.*)$ two/$1 [L]

All requests for the host domain-one.com are rewritten (not R=redirected) to the one/ directory, so long as they haven't already been rewritten there (the second RewriteCond). Same story for domain-two.com. Note the inconsistency in the RewriteCond statement; !^/dir-name and !^dir-name should both work fine.

Also note, with such a simple domain & folder naming scheme, you could easily merge these two rule sets together. This would be unlikely in the real world though, which is why I left them separate; but still, worth noting.

Other general settings and php directives can also go in this root .htaccess file, though if you have any further rewrite you'd like to perform; short URL's, htm to php conversion and what-not; it's probably easier and clearer to do those inside the sub-directory's .htaccess files.
User avatar
Web Guru
 
Posts: 94
Joined: March 24th, 2008, 7:59 am
Location: Lahore, Pakistan


Re: Multiple Domains in one root

Postby itrana123 » June 19th, 2009, 1:00 pm

I have a also a query similarily to that one. My problem is that I have a lot of domains in one root. I want to force www in the begining of all the domains pointed to that root folder. can any one help. Its a matter of urgent.
itrana123
 
Posts: 3
Joined: August 6th, 2008, 8:45 am
Location: Lahore


Re: Multiple Domains in one root

Postby itrana123 » September 1st, 2009, 4:53 am

Finally :!: I got the solution by myself wandering over the net. Here is the solution:P

Code: Select all
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
itrana123
 
Posts: 3
Joined: August 6th, 2008, 8:45 am
Location: Lahore


Return to Board index

Return to SEO - Search Engine Optimization

Who is online

Users browsing this forum: No registered users and 0 guests