2

Using Url Rewrite, I'm trying to redirect /foo_bar/* to /foo/*. I've tried this:

<rule name="Redirect foo_bar to foo" stopProcessing="true">
    <match url="(.*)" />
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
        <add input="{HTTP_URL}" pattern="^/foo_bar/(.*)" />
    </conditions>
    <action type="Redirect" url="/foo/{R:1}" />
</rule>

But this just redirects to /foo/foo_bar/*. Where am I going wrong?

Jonathan
  • 1,309
  • 2
  • 22
  • 29

1 Answers1

4

First of all, you specify a rule to match all requests (.*), then you add a condition for a specific url.

You should have your limiting criteria in the match:

<match url="^/foo_bar/(.*)" />

then you don't need the condition anymore. You use conditions only for additional criteria not based on the URL.

Secondly {R:1} refers back to the whole url from the match, so if you have /foo_bar/ in the url thats what is in {R:1}, that explain why it redirects to /foo/foo_bar/.

With your new match rule, {R:1} holds what's in (.*), not the whole Url, so it should work.

Peter Hahndorf
  • 14,058
  • 3
  • 41
  • 58