Forum Moderators: open

Message Too Old, No Replies

Unusual redirect script

I need some help with a script to detect location...

         

JimBrashear

7:12 pm on Aug 23, 2005 (gmt 0)

10+ Year Member



I work for a rather large web development company, and have come upon a wierd problem. The way our server is set up, we save our websites in the root of our own site as a subfolder, and then set up with IIS where the domain is supposed to go. For example, www.generationsclothing.net is really loading www.explorewisconsin.com/generationsclothing - both locations are exactly the same thing and both work if you type then into the browser.

Is there a javascript out there to detect the location people are viewing the page at and redirect to the domain? For example a script that if someone was looking at the www.explorewisconsin.com/generationsclothing it would automatically detect the explorewisconsin.com part and redirect them to the domain?

We're dealing with a nightmare concerning some database connections having them point to two places and this would be the easy fix.

Thanks a million!
Jim

ChadSEO

8:15 pm on Aug 23, 2005 (gmt 0)

10+ Year Member



Jim,

Welcome to WebmasterWorld!

The variable "window.location" should contain the current URL. It contains the full URL, but you could certainly just check against the first part of it.

Chad

JimBrashear

8:35 pm on Aug 23, 2005 (gmt 0)

10+ Year Member



So if I did something like:

if(window.location!= "http://www.explorewisconsin.com/generationsclothing"){
window.location = "http://www.generationsclothing.net"
}

It should redirect correct? If so, how would I make it kind of a wildcart situation where [explorewisconsin.com...] would send them to the generationsclothing.net?

ChadSEO

8:48 pm on Aug 23, 2005 (gmt 0)

10+ Year Member



Jim,

You'd want to do something like this:

if (window.location.search(/www\.example\.com/){
window.location = "http://www.example2.com";
}

Note that "search" uses regular expressions, so you have to escape the periods (hence the \'s). Also, it's against the TOS (Terms of Service) to post any specific domains, just for future reference.

Chad

JimBrashear

9:50 pm on Aug 23, 2005 (gmt 0)

10+ Year Member



Thanks a million! Sorry about the TOS violation - I'm a stupid newby and didn't realize, I'll keep that down in the future - thank's again for the help, and great forum! :-)