I have read the top 30 Google hits for several combinations of IIS rewrite map condition
and so on, but I can\'t find any decent documentation, either on a micros
Firstly, don't use dot, it matches everything and is naturally greedy. Use character negation instead: ([^\n]+)
.
Try this, then re-run, and if that doesn't work, try adding /?
again on the pattern
attribute.
This should do it:
<rewrite>
<rewriteMaps>
<rewriteMap name="ShortURLs">
<add key="terms" value="/en-us/terms-and-conditions/"/>
<add key="privacy" value="/en-us/privacy-and-cookies/"/>
<add key="buy" value="/en-us/where-to-buy/"/>
</rewriteMap>
</rewriteMaps>
<rules>
<rule name="Short URL redirects">
<match url="^(.+?)/?$" />
<conditions>
<add input="{ShortURLs:{R:1}}" pattern="(.+)" />
</conditions>
<action type="Redirect" url="{C:1}" appendQueryString="true"/>
</rule>
</rules>
</rewrite>
You were quite close; I only needed to make three small changes:
+?
in the rule's match{R:1}
in the condition inputI share your experience in having trouble finding decent documentation; I had to experiment my way through, with help from the following articles: