Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detect address typed in address bar on entry? 1

Status
Not open for further replies.

lonechicken

Programmer
Sep 25, 2001
18
0
0
US
How would I get the address that a user typed into the address bar when they visit my site? Why?

Say I have a site in which the DNS points multiple domains to the same ip address. Let's say both and both point to the same place. How would I detect which one the user typed in to get to that page?

This is so I can then redirect, say, site2.com users to a subfolder, but don't redirect mysite.com users. Some web hosts charge a certain small fee for forwarding a domain to a subfolder of another domain's site, while other hosts don't even let you do that much.
 
You could try javascript for this...(I'm sure there are other ways :) )
Code:
<script language=javascript>
  alert(window.location); // just to show you what was typed in
  if (window.location == &quot;[URL unfurl="true"]http://www.site2.com&quot;[/URL] || window.location == &quot;[URL unfurl="true"]http://www.site2.com/&quot;)[/URL]
    window.location = &quot;[URL unfurl="true"]http://www.site2.com/site2/login.asp&quot;;[/URL]
  else
    window.location = &quot;[URL unfurl="true"]http://www.mysite.com/login.asp&quot;;[/URL]
</script>
 
Thanks, I didn't even think about using JS! This should take care of pretty much all users, but just in case someone has javascript turned off in their browser... Can this same process be done in ASP?
 
Try this something like this...
<%
dim URL, newFile
URL = Request.ServerVariables(&quot;SERVER_NAME&quot;)
newFile = &quot; & URL
if URL = &quot; then
newFile = newFile & &quot;/site2/login.asp&quot;
else
newFile = newFile & &quot;/login.asp&quot;
end if
Response.Redirect newFile

%>
 
Thanks again jlsmithprism!
After drudging through some caching issues, I think the ASP version works. I guess those semicolons in the code you listed weren't supposed to be there.
 
You're right they're not....something happened when I posted cause I didn't put them there :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top