Get current page url (use rewrite url)

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

How can I get the current page url in classic asp?

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

so here I want the current URL of the page http://www.site.com/home/page

Please help me. Thanks.

+7
source share
3 answers

You can try to output all ServerVariables as follows:

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

The URL you are looking for may already exist. We use the Rewrite module, and there is a ServerVariable named HTTP_X_ORIGINAL_URL that contains a rewritten URL, for example. "/ home / page" in your example.

The protocol ( HTTPS=ON/OFF ) and server ( SERVER_NAME ) can also be found in ServerVariables.

+11
source

There is no favorite feature that does all this.

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 an additional 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 this works for you.

+18
source

If you use Rewrite URLs, these URLs can only be restored 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) 
0
source

All Articles