Trondh
Trondh

Reputation: 3341

URL rewrite multiple excludes

I'm trying to write a IIS Url rewrite rule that redirects all requests except two, and I can't figure it out.

What I'm trying to accomplish: http://server/healthcheck.aspx --> not redirected http://server/idsrv2/2/stuff --> not redirected http://server/stuffstuff --> redirect to http://server/idsrv2/stuffstuff

This is the rule I have so far, but it's not kicking in: <rule name="Redirect everything to idsrv/2" patternSyntax="Wildcard" stopProcessing="true"> <match url="^$" /> <conditions logicalGrouping="MatchAny"> <add input="{REQUEST_URI}" pattern="^(.*)healthcheck" negate="true"/> <add input="{REQUEST_URI}" pattern="^(.*)idsrv2" negate="true" /> </conditions> <action type="Redirect" url="idsrv2{R:1}" appendQueryString="true"/> </rule>

Any help appreciated!

Upvotes: 0

Views: 763

Answers (1)

Victor Leontyev
Victor Leontyev

Reputation: 8736

Logical grouping in your rule should be MatchAll. I've changed you rule a bit and this should work in your case:

<rule name="Redirect everything to idsrv/2" stopProcessing="true">
    <match url="(.*)" />
    <conditions logicalGrouping="MatchAll">
        <add input="{REQUEST_URI}" pattern="^/healthcheck" negate="true"/>
        <add input="{REQUEST_URI}" pattern="^/idsrv2" negate="true" />
    </conditions>
    <action type="Redirect" url="idsrv2/{R:0}" appendQueryString="true" />
</rule>

Upvotes: 3

Related Questions