'IIS Web.config Rewrite rules - Redirect rules with - or + chars
https://someserver.com/path01/2011/abc+and+def/88722
https://someserver.com/path01/2011/abc-and-def/88722
I have several URLs that I need to create a redirect rule. I need to remove "2011" from the url and change the URL... I got most of it working but I can't figure out how the "-" or "+" needs to be written and how to combine into one rule
<rule name="Redirection 1" stopProcessing="true">
<match url="test-catalog/([0-9]*)//abc-and-def/([0-9]*)"/>
<action type="Redirect" url="https://someserver.com/path01/overview/{R:2}#/abc-and-def"/>
</rule>
<rule name="Redirection 2" stopProcessing="true">
<match url="test-catalog/([0-9]*)//abc+and+def/([0-9]*)"/>
<action type="Redirect" url="https://someserver.com/path01/overview/{R:2}#/abc-and-def"/>
</rule>
I tried to use this use rule but it's not working !!
<rule name="Redirection rule " stopProcessing="true">
<match url="test-catalog/([0-9]*)//abc([-+]*)and([-+]*)def/([0-9]*)"/>
<action type="Redirect" url="https://someserver.com/path01/overview/{R:4}#/abc-and-def"/>
</rule>
Any ideas on how to solve this issue?
Solution 1:[1]
Because "+"
and "-"
are reserved words in regular expressions, they have special meanings. If you need to use them as normal characters, you should add the escape character "\"
in front of the characters.
That is, "\+"
means the character "+"
; "\-"
means the character "-"
;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | JennyDai |