Get current url of the page (used URL Rewrite)

asp-classicvbscript

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.

Best Answer

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.

Related Topic