Reputation: 95
I am having an issue trying to get the rewrite working in IIS7 web.config.
I need URLs like /err/interaccess to be rewritten to /err/404new.asp (not a redirect,as I don't want to expose the file.
I tried the following and it only works if I use /interaccess but not /err/interaccess
<rule name="Rewrite Interaccess Error" enabled="true" stopProcessing="true">
<match url="^tinteraccess$" />
<action type="Rewrite" url="/err/404new.asp" />
</rule>
Any idea on why? I tried to find documentation on this and could not find anything regarding this usage.
Upvotes: 1
Views: 1963
Reputation: 6138
The magic is in the regular expression of the <match>
tag. To make it match your exact URL you would use:
<rule name="Rewrite Interaccess Error" enabled="true" stopProcessing="true">
<match url="^err/interaccess$" />
<action type="Rewrite" url="/err/404new.asp" />
</rule>
If you would want to match everything under /err/
you would use:
<rule name="Rewrite Interaccess Error" enabled="true" stopProcessing="true">
<match url="^err/" />
<action type="Rewrite" url="/err/404new.asp" />
</rule>
This is all very well documented, e.g.: http://www.iis.net/downloads/microsoft/url-rewrite (see Related Learning)
Upvotes: 1