Reputation: 1030
I'm replatforming an online shop, and part of that process is writing 301 redirects for old links customers may have bookmarked to hit their new addresses. All of them work apart from the ones in which the old address contains the %
character. It seems to somehow be interfering with the regex. The rule is:
<rule name="Custom 41 redirect" stopProcessing="true">
<match url="^c80/How-to-%20Use-Shop-Name\.aspx" ignoreCase="true" />
<action type="Redirect" url="/how-to-use-shop-name" redirectType="Permanent" />
</rule>
Testing using the built in regex tester in IIS tells me that hitting
/c80/How-to-%20Use-Shop-Name.aspx
Matches the pattern, yet the rule fails to redirect me when I hit that address.
I should also stress that there are about 400 rewrites in my web.config, but only the 3 which contain the %
character break.
Upvotes: 2
Views: 1387
Reputation: 626802
Since the string that is tested against the regex is already Url-decoded, you no longer need the %20
in your regex. Just use a plain space:
<match url="^c80/How-to- Use-Shop-Name\.aspx" ignoreCase="true" />
Also, in case the space is optional, you may use a ?
after it:
<match url="^c80/How-to- ?Use-Shop-Name\.aspx" ignoreCase="true" />
Upvotes: 3