Reputation: 11679
I have a rewrite that is set up to handle multiple different user agents, and I want to be able to match my rule on any of them. However, any url that matches one of these must also match another rule (an IP address). However, I can't find any documentation on how to do this. Can anyone make any suggestions on how I can do this?
Below is an example of what I'm trying to achieve. I know that this will fail because the conditions
node has already been declared more than once.
So, in essence it's a redirect when any of the {HTTP_USER_AGENT}
rules and any of the {REMOTE_ADDR}
rules are matched.
<rule name="Mobile UA redirect" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<!-- Any of these can be matched -->
<add input="{HTTP_USER_AGENT}" pattern="Android" />
<add input="{HTTP_USER_AGENT}" pattern="BlackBerry" />
<!-- ... more user agents... -->
</conditions>
<!-- Here, similarly, any one of these rules can be matched, but one of the rules above must also match one of the rules below. -->
<conditions logicalGrouping="MatchAny">
<add input="{REMOTE_ADDR}" pattern="127.0.0.1" />
<add input="{REMOTE_ADDR}" pattern="192.168.0.1" />
</conditions>
<action type="Redirect" url="http://mob.mydomain.com/{R:0}" appendQueryString="true" />
</rule>
Any help on how I can do this would be greatly appreciated!
Upvotes: 4
Views: 2315
Reputation: 11377
What about smth like the following, placed at the bottom:
<rule name="MobileRestricted" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{REMOTE_ADDR}" pattern="127.0.0.1" negate="true" />
<add input="{REMOTE_ADDR}" pattern="192.168.0.1" negate="true" />
</conditions>
<action type="None"/>
</rule>
<rule name="Mobile UA redirect" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<!-- Any of these can be matched -->
<add input="{HTTP_USER_AGENT}" pattern="Android" />
<add input="{HTTP_USER_AGENT}" pattern="BlackBerry" />
<!-- ... more user agents... -->
</conditions>
<action type="Redirect" url="http://mob.mydomain.com/{R:0}" appendQueryString="true" />
</rule>
Not a single rule, but no more than two )
Upvotes: 2