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 on 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: 66
Joined: March 24th, 2008, 7:59 am
Location: Lahore, Pakistan

Return to SEO - Search Engine Optimization

Who is online

Users browsing this forum: No registered users and 0 guests

cron