Forum Moderators: open

Message Too Old, No Replies

Actual URL in browser

Figuring out what the actual URL is that is displayed in the browser

         

McClaw

2:34 pm on Apr 25, 2006 (gmt 0)

10+ Year Member



Hi all

I am currently struggling with a situation where I have two pages in google (where only one should exist).

These pages are www.example.com and www.example.com/default.aspx

I want to be able to redirect from the www.example.com/default.aspx one to www.example.com if I find it in the URL.

I have been playing around with getting headers and Server variables and seeing if any of them contain "default.aspx" but because default.aspx is the default page I cant find one that gives me the exact URL in the Address bar.

Any one tried someting like this before?

paulanthony

5:34 pm on Apr 25, 2006 (gmt 0)

10+ Year Member



<%

If InStr( Request.ServerVariables("HTTP_REFERER"), "google") > 0 Then

If Request.ServerVariables("URL") = "/default.aspx"
Response.Redirect("somepage")
End If

End If

%>

something like that

mattglet

7:04 pm on Apr 25, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you concat these 2 server variables, you will get the URL:

Request.ServerVariables("HTTP_HOST") & Request.ServerVariables("PATH_INFO")

McClaw

8:50 am on Apr 26, 2006 (gmt 0)

10+ Year Member



I have tried response writing all the ServerVariables, Request.Params and Request.Headers, and I didnt find any thing that would destinguish www.eample.com from www.example.com/default.aspx

here are all the vars that might have been useful and their values, am I missing anything?

Is there perhaps someting else that I havent tried?

www.example.com
PATH_INFO : /Default.aspx
PATH_TRANSLATED : C:\somefolder\Default.aspx
SCRIPT_NAME : /Default.aspx
URL : /Default.aspx
HTTP_HOST : www.example.com

www.example.com/Default.aspx
PATH_INFO : /Default.aspx
PATH_TRANSLATED : C:\somefolder\Default.aspx
SCRIPT_NAME : /Default.aspx
URL : /Default.aspx
HTTP_HOST : www.example.com

As you can see both give exactly the same results.

Here is the code I used to query all available data


Response.Write("<b>ServerVariables</b><br>____________________________<br>");
foreach (string itm in Request.ServerVariables){
if(Request.ServerVariables[itm].ToString().Trim().Length > 0){
Response.Write(itm + " : " + Request.ServerVariables[itm] + "<br><br>");
}
}
Response.Write("<b>Headers</b><br>____________________________<br>");
foreach (string itm in Request.Headers){
if(Request.Headers[itm].ToString().Trim().Length > 0){
Response.Write(itm + " : " + Request.Headers[itm] + "<br><br>");
}
}
Response.Write("<b>Params</b><br>____________________________<br>");
foreach (string itm in Request.Params){
if(Request.Params[itm].ToString().Trim().Length > 0){
Response.Write(itm + " : " + Request.Params[itm] + "<br><br>");
}
}