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.
-
User enters
http://savecontoso.com/files/123456789/somefile.htmlin the browser address bar. -
User is redirected to
http://savecontso.com/default.aspx?url=(results ofurl="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 IIS 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:
{R:1}will only match(.*)in your pattern, and will never matchfiles/123...files/\d+...and not/files/\d+...Try this one instead (works fine for me):