Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get current url of the page (used URL Rewrite)

I am working on classic asp application. I have use URL rewrite on some pages.

How can i get current url of the page in classic asp?

Example: http://www.site.com/page.asp ---> url rewrite in IIS ---> http://www.site.com/home/page

so here i want current url of the page which is http://www.site.com/home/page

Please help me. Thanks.

like image 261
Maddy Avatar asked Mar 13 '13 20:03

Maddy


Video Answer


3 Answers

There's no fancy one function that does it all.

First you need to get the protocol (if it is not always http):

Dim protocol
Dim domainName
Dim fileName
Dim queryString
Dim url

protocol = "http" 
If lcase(request.ServerVariables("HTTPS"))<> "off" Then 
   protocol = "https" 
End If

Now the rest with optional query string:

domainName= Request.ServerVariables("SERVER_NAME") 
fileName= Request.ServerVariables("SCRIPT_NAME") 
queryString= Request.ServerVariables("QUERY_STRING")

url = protocol & "://" & domainName & fileName
If Len(queryString)<>0 Then
   url = url & "?" & queryString
End If

Hope it works for you.

like image 71
Konrad Avatar answered Oct 27 '22 13:10

Konrad


You can try to output all ServerVariables like so:

for each key in Request.Servervariables
  Response.Write key & " = " & Request.Servervariables(key) & "<br>"
next

Maybe the URL you seek is already there. We use the Rewrite module and there is a ServerVariable called HTTP_X_ORIGINAL_URL that contains the rewritten URL path, e.g. "/home/page" in your example.

Protocol (HTTPS=ON/OFF) and Server (SERVER_NAME) can also be found in the ServerVariables.

like image 21
gpinkas Avatar answered Oct 27 '22 15:10

gpinkas


If you use URL Rewrite, the url data can only be retrieved in this way:

Request.ServerVariables("HTTP_X_ORIGINAL_URL")

Example

Dim domainName, urlParam
domainName = Request.ServerVariables("SERVER_NAME") 
urlParam   = Request.ServerVariables("HTTP_X_ORIGINAL_URL")
response.write(domainName & urlParam)
like image 40
Entwickler Mak Avatar answered Oct 27 '22 13:10

Entwickler Mak