Forum Moderators: open
My company owns 8 or 9 domains, and they all point to our main site. Is it possible to use JS to redirect to a specific page within the site based on which domain name they use?
Example: Our main site is MainDomain.com. If the viewer goes to SecondaryDomain.com (which just currently goes to the default MainDomain.com page), can I redirect them to MainDomain.com/secondary.html?
Thanks!
[edited by: feenomenal at 8:00 pm (utc) on July 11, 2003]
The "location" object gives lots of properties for reading the current URL such as "href" - the complete URL, "pathname" - the path portion "port", "protocol", etc.
For a good discussion of all of these, look to www.w3schools.com
Once you have a handle on where the user is, you can use that for a wide variety of purposes.
Do you know about .htaccess? This might give you a better solution. Have a search on the forums for "redirecting with .htaccess" and similar phrases, and you'll come away with all kinds of ideas.
While it means getting your head round something else (if you don't know it already) it will work for customers that are not JS-enabled, and may end up as a simpler solution.
<?php
$domain = $_SERVER["HTTP_HOST"];
//redirecting clauses
if (strpos("secondarydomain",$domain)) $goto="secondary.htm";
if (strpos("tertiarydomain",$domain)) $goto="tertiary.htm";
if ($goto)
{
header("HTTP/1.1 301 Moved Permenantly");
header("location: http://www.maindomain.com/$goto");
}
else
{
?>
*NORMAL INDEX PAGE*
<?php
}
?>