Click to See Complete Forum and Search --> : domain name/javascript question


noslenwerd
04-27-2005, 10:13 AM
Hello everyone, i am a newb to the forums, i work as a web developer in Pittsburgh, PA...

anyways on with my question

We have a company that changed thier name, as well as thier website. We made a page (index.asp) on the old site that lets users know the site has changed, and redirects them to the new one, this page works no problem in our test environment... Problem is, they are running off the same IP address. Oh and if it matters we are using IIS 5.

I want something that will read the domain name of a request, possibly in Javascript, and perform some operation based on the value of that domain. The user requests a web page, say index.asp, and that web page should contain the code that reads the domain name and then redirect users based on that domain name.

Thanks ahead of time for any help.

ATBS
04-27-2005, 01:23 PM
HI
I am a newb to the forum too - welcome.
I use javascript location.hostname and parse the returned string for the information I need.
Maybe that'll help.

noslenwerd
04-27-2005, 02:41 PM
HI
I am a newb to the forum too - welcome.
I use javascript location.hostname and parse the returned string for the information I need.
Maybe that'll help.

ok thanks, i think more specifically what I'm asking is...

is there a way to catch when someone is putting in the old URL, and have a function that recognizes they are doing so, and have that function send them to the .asp file we created that tells the user the site has changed...Keep in mind both sites now look exactly the same because they are coming from the same files and both have the same IP address...

Thanks!

ATBS
04-27-2005, 04:21 PM
Hi,
Yeah, like I said, use location.hostname in your script and use it in the body onload event.
Check out www.bestfloridarentals.com, www.bestorlandorentals.com and www.bestdisneyrentals.com. They are all the same site using a javascript function to parse which domain the user came in on and loads the appropriate image/text accordingly.

noslenwerd
04-28-2005, 08:36 AM
Hi,
Yeah, like I said, use location.hostname in your script and use it in the body onload event.
Check out www.bestfloridarentals.com, www.bestorlandorentals.com and www.bestdisneyrentals.com. They are all the same site using a javascript function to parse which domain the user came in on and loads the appropriate image/text accordingly.


Ahh great thanks so much, i see now in the source code, and the domain.js file, where it checks to see where they enter from.

You're a life saver, thanks again

David Harrison
04-28-2005, 09:00 AM
WHAT ARE YOU DOING??? Why use a client-side language which many people do not have enabled (including me) when you have a server-side language readily available? Just check the domain name with ASP and if it's the wrong one, use a server-side redirect.

noslenwerd
04-28-2005, 09:13 AM
WHAT ARE YOU DOING??? Why use a client-side language which many people do not have enabled (including me) when you have a server-side language readily available? Just check the domain name with ASP and if it's the wrong one, use a server-side redirect.

:confused:

Not really sure what you mean. I don't know the difference between server/client side languages. Or how I would check the domain name with asp...

Sorry I'm a n00b when it comes to javascript, go easy on me. Javascript usually isn't something I deal with but the two guys who usually deal with this have a deadline to meet and are super busy.

scragar
04-28-2005, 09:24 AM
I'm not sure if this will work perfectly, so you'll have to test it first...<%
Dim referrer As String
referrer = Request.ServerVariables("http_referrer")
Dim objRegExpr
Set objRegExpr = New regexp
objRegExpr.Pattern = "the new sites domain, replacing . with \."
objRegExpr.Global = True
objRegExpr.IgnoreCase = True
if(objRegExpr.Execute(referrer).Count = 0)then
response.redirect("the page URL to go to...")
end if
%>

David Harrison
04-28-2005, 11:06 AM
I think I see what you're trying to do there, but that assumes that it's exactly the same web-site, just on a different domain, but I don't think it is.

Here's a simple piece of code that you can just package away at the start of index.asp, if the domain is wrong then it will redirect users to the correct domain and the user probably won't even notice.<%

dim oldDomain, newDomain
oldDomain = "oldSite.com"
newDomain = "newSite.com"

if replace(request.ServerVariables("HTTP_HOST"), "www.", "") = oldDomain then

response.redirect "www." & newDomain

end ifEdit: Made a couple of mistakes, just caught them. All present and correct now.

noslenwerd
04-28-2005, 11:53 AM
I think I see what you're trying to do there, but that assumes that it's exactly the same web-site, just on a different domain, but I don't think it is.

Here's a simple piece of code that you can just package away at the start of index.asp, if the domain is wrong then it will redirect users to the correct domain and the user probably won't even notice.<%

dim oldDomain, newDomain
oldDomain = "oldSite.com"
newDomain = "newSite.com"

if replace(request.ServerVariables("HTTP_HOST"), "www.", "") = oldDomain then

response.redirect "www." & newDomain

end ifEdit: Made a couple of mistakes, just caught them. All present and correct now.


Thanks a lot guys for all your help... this forum is more helpful than most I have tried...

Anyways yes.. they are the SAME exact websites, same IP addresses, so when you go to each different URL the pages are exactly the same, therefore if i change one index.asp, both sites get changed... And David Harrison, that code is very helpful but, the problem is the customer who these are being modified for... wants a page displayed that tells them that they have changed thier company/URL name, and have it automatically redirect them to the new site (i have already made the asp file that redirects them to the new site, it works) So therefore they want the user to notice the change. The problem is calling that ASP file i already made ONLY when someone goes to the old website URL... But if they just go directly to the new URL, just have nothing happen... any suggestions? Should i just rename the ASP file i made to redirect the user to the new page... to redirect.asp? And somehow have that called up when someone enters in the old URL?

Thanks again guys... i really appreciate it (this is my second week at this job and you are all helping me out a lot)

noslenwerd
04-29-2005, 07:21 AM
bump.... please... someone?

noslenwerd
05-02-2005, 07:28 AM
bump.... :(

noslenwerd
05-03-2005, 07:56 AM
thanks again for all your help guys... i can't figure it out though...