开发者

IIS URL Rewriting At Initial Host Request

I am having a problem with an IIS7 Integrated Pipeline URL Rewrite. For my particular scenario I need to rewrite/redirect part of the initial request as follows.

  1. User enters http://savecontoso.com/files/123456789/somefile.html in the browser address bar.

  2. User is redirected to http://savecontso.com/default.aspx?url= (results of url="default.aspx?url={R:1}")

This currently works as expected only if I create the initial request as such, http://savecontoso.com/default.aspx/files/123456789/somefile.html.

I must note that there is no actual directory of /files/ nor /123456789/ nor any file named somefile.html on the server. I simply need that entire path and filename appended to a query string.

This is my first day working with redirect/rewrite functions using 开发者_如何学JAVAIIS instead of page code behind and I have looked all around learn.iis.net, Google etc to no avail. I understand that rewriting takes place before page requests but for some reason my particular code requires a page request before firing the redirect.

I suspect it is because I am not triggering conditions at the initial request?

<rewrite>
<rules>
<rule name="1" stopProcessing="true">
<match url="(.*)(/files/\d+/.*html$)" />
<action type="Redirect" redirectType="Permanent" url="default.aspx?url={R:1}" />
</rule>
</rules>
</rewrite>


Most likely it does not work because of your match pattern:

  • the {R:1} will only match (.*) in your pattern, and will never match files/123...
  • URL in match pattern always starts with no leading slash: should be files/\d+... and not /files/\d+...

Try this one instead (works fine for me):

<rule name="1" stopProcessing="true">
    <match url="^files/\d+/.*\.html$" />
    <action type="Redirect" url="default.aspx?url={R:0}" redirectType="Permanent" />
</rule>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜