11

Is it possible to use reg ex in a rewrite map? For example:

<rewriteMap name="Redirects">
   <add key="/blah/(.*)" value="/blah/{R:1}" />
</rewriteMap>

Or is there a way to handle this approach? Currently, I have a rule set up to match on everything and then use the rewrite map to map to new urls. I would like to capture everything under a directory e.g. resource files (blah)... without having to manually to do this for them all.

Sam Gooch
  • 131
  • 1
  • 4
  • i'm sure you've already read it, but just incase, there is some helpful stuff here: http://learn.iis.net/page.aspx/465/url-rewrite-module-configuration-reference/ – Robbie Apr 11 '12 at 12:56

1 Answers1

3

Unfortunately not, you'll need to create a rule to use regular expressions.

Notice that there is no obvious common pattern in the keys and their relation to values. This means that it is not possible to use regular expressions or wildcards to define URL transformation logic. http://www.iis.net/learn/extensions/url-rewrite-module/using-rewrite-maps-in-url-rewrite-module

Jay
  • 884
  • 11
  • 16
  • The mention that you quote here is a reference to the examples they're giving earlier in that page, so I don't believe it's a "regex will never work" so much as "regex won't work for this example". That said, I can't find any information about whether or not regex will work "ever", as the documentation for rewrite maps appears to be non-existent :/ – Owen Blacker Mar 14 '14 at 10:43
  • I correct myself — the documentation is not non-existent, but it's not very comprehensive. There is more documentation at [URL Rewrite Module Configuration Reference](http://www.iis.net/learn/extensions/url-rewrite-module/url-rewrite-module-configuration-reference), though it does not address this point. – Owen Blacker Mar 24 '14 at 13:49
  • I think a better quote is from the summary: "The rewrite maps allow you to reduce the number of rewrite rules when rewrite and redirect URL's are static and rewriting logic cannot be expressed by using any pattern matching techniques." – Zhaph - Ben Duguid Jan 26 '21 at 22:00