HomeUncategorizedMultiple Domains on One Host

If you are like many people, you have several domains and want to save money with hosting costs.  One method of hosting multiple domains on one site is to use redirection.

The method described here works best if you want a domain typable or linkable by users, but don’t care about search engine placement being traced back to the original domain.  For the example below, I’m using redirected.com as a domain to redirect to a subdirectory of existing domain mybase.com.  If you want search engines to find “redirected.com” directly (NOT as a subdirectory under mybase.com) then this method won’t work.  Feel free to contact me for other solutions.

When someone enters a domain in the address box of a browser, typically an “index.html” is loaded from the root directory for that domain.  You can place the code presented here (located just before your </head> tag), and the user who types in “www.redirected.com” will be redirected to “www.mybase.com/redirected/index.html”.

This simple method does NOT work for multiple documents on the redirected.com domain .. it only allows you to get into the single file (typically index.html) in that domain.  You can then index other documents in the directory and they will be found appropriately, so the site CAN contain multiple pages; the sub-pages will just not be seen as in the redirected.com domain.

<script>
//  Script prepared by KNF & Associates  http://www.knfa.net
//  If you use this script please keep these two lines intact.
function isValidURL(myPointer) {
        return (myPointer > 0  &&  myPointer < 12);
}

if (isValidURL(document.URL.indexOf("redirected.com")))
        location.href = "http://www.mybase.com/redirected/index.html";
if (isValidURL(document.URL.indexOf("mail.redirected.com"))) {
        location.href = "http://www.mybase.com/redirected/mail/index.html";
        exit;
} else if (isValidURL(document.URL.indexOf("mysecond.org"))) {
        location.href = "http://www.mybase.com/mysecond/index.html";
        exit;
}
</script>

A few notes on this script.  You can redirect as many locations to specific pages as you desire by just including pairs of redirection code.  I’ve used this for redirecting things like “http://mail.redirected.com” to a specific page on the site .. it’s easier for people to remember that URL than it is to type in “http://redirected.com/mailman/mailstart.php”, for example.

You need to be careful the strings you put inside of the indexOf(…) statement.  What this script does is look in the document’s URL and see if that string is found within the first 12 characters of the URL. If you enter (for an absurd example) “base.com” as your redirected domain, then when it redirects it to “mybase.com”, “base.com” is found within mybase, so it will redirect it again, and you won’t ever see anything.

Note that I’m not including the “www.” in the searched-for domains.  This allows EITHER “http://redirected.com” OR “http://www.redirected.com” to be redirected to the appropriate file.


Good luck!

Norm Fisher
June 16, 2003

Comments are closed.