Click to See Complete Forum and Search --> : Redirect from a specific URL


aabrams5
12-03-2002, 11:24 AM
Hello,

I have a website with multiple DNS entries that point to the site. Is it possible to write a some code into my index page that will identify the typed URL and redirect users to a new page?

e.g. of the result:
A user types www.mainsite.com and is taken to the index page for the site OR a user types www.site2.com and is taken to the index page which then redirects the user to the new page.

- Any ideas?

Thank you in advance!

AdamGundry
12-03-2002, 01:26 PM
There is a property of the window.location object, location.href, that contains the current URL. So you could use something like this:

if (location.href == "http://www.site2.com/"){
location.href = "http://www.mainsite.com/site2"}

The problem with this approach is that if the user enters something different, like http://www.site2.com (note lack of trailing slash) a match will not result. You could probably use regular expressions to make this script more reliable.

Location object details (http://developer.netscape.com/docs/manuals/communicator/jsref/wina1.htm)

Regular Expression details (http://developer.netscape.com/docs/manuals/communicator/jsref/corea3.htm)

Hope this helps

Adam