How to get the “originally requested” URL when using IIRF URL Rewriting Engine

这一生的挚爱 提交于 2019-12-10 19:35:29

问题


I am using Iconic's IIRF URL Rewriting Engine on IIS and the "fancy" URLs are something like this:

http://some-website.com/some-function/418/some-keyword-rich-filename.html

This example URL corresponds to:

http://some-website.com/some-function.asp?SOME-ID=418

Now inside the some-function.asp file I need to know the page that was requested by the browser. I went through all IIS variables but wasn't able to find the value /some-function/418/some-keyword-rich-filename.html inside any of them.

As a side note, I need this information to send 301 redirect to browsers. E.g. if the browser requests:

http://some-website.com/some-function/418/index.html

I first need to send the browser to:

http://some-website.com/some-function/418/some-keyword-rich-filename.html

And this is why I need the original url for comparison.


回答1:


For IIRF, this is called unmangling and can be achieved by using the modifier U.

From the IIRF manual:

U = Store original url in server variable HTTP_X_REWRITE_URL

Simply add the modifier U to the RewriteRule for which you would like to retain the original url. For example:

RewriteRule ^/some-function/(\d+)/(.*)$ /some-function.asp?SOME-ID=$1 [I,U,L] 

Then, in the code of your page some-function.asp, you may access the original url like this (classic ASP):

Request.ServerVariables("HTTP_X_REWRITE_URL")


来源:https://stackoverflow.com/questions/3895956/how-to-get-the-originally-requested-url-when-using-iirf-url-rewriting-engine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!