Forum Moderators: open

Message Too Old, No Replies

JS redirect based on requested URL

How to utilize our multiple domains to go to specific pages within our site

         

feenomenal

7:45 pm on Jul 11, 2003 (gmt 0)

10+ Year Member



Well, I'm brand new to these forums (been here about 5 minutes) and I have a question. My webhost hasn't been any help in this, so I'm trying to find a javascript solution.

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]

txbakers

7:48 pm on Jul 11, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi and welcome to the Webmaster World Forums!

Yes, you can redirect anywhere you want with javascript:

the command is location.href="mynewsite.htm" or whatever you want it to be.

feenomenal

7:59 pm on Jul 11, 2003 (gmt 0)

10+ Year Member



Thanks!

But how do I have it check the requested URL and use that to go to a certain page?

txbakers

8:13 pm on Jul 11, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can "read" the URL using javascript as well.
var currentUrl = location.href;

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.

TheDoctor

8:39 pm on Jul 11, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to the Webmaster World Forums, feenomenal.

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.

feenomenal

10:26 pm on Jul 12, 2003 (gmt 0)

10+ Year Member



the .htaccess stuff is pretty interesting, and I didn't realize you could redirect there. I have used that for my 404 error page, but nothing else. Is there a good place I could go to read up on what you can do with that page? I searched around a bit, but didn't find much.

killroy

11:08 pm on Jul 12, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try a google search for

htaccess redirect 301 site:www.webmasterworld.com

That should do the trick ;)

SN

vincevincevince

7:49 am on Jul 13, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



i'd try the php forum if you can't fix it:
the php solution is to put this around your index page (if you have php on your server)

<?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
}
?>