Reputation: 927
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.
Upvotes: 12
Views: 33924
Reputation: 31
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)
Upvotes: 3
Reputation: 2591
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.
Upvotes: 19
Reputation: 1014
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.
Upvotes: 21