4

我有一个重写设置来处理多个不同的用户代理,我希望能够在其中任何一个上匹配我的规则。但是,任何匹配其中之一的 url 也必须匹配另一个规则(IP 地址)。但是,我找不到任何有关如何执行此操作的文档。谁能对我如何做到这一点提出任何建议?

下面是我想要实现的一个例子。我知道这将失败,因为该conditions节点已被多次声明。

因此,本质上它是当任何{HTTP_USER_AGENT}规则任何{REMOTE_ADDR}规则匹配时的重定向。

<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>

任何有关我如何做到这一点的帮助将不胜感激!

4

1 回答 1

2

像下面这样的东西呢,放在底部:

<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>

不是一条规则,但不超过两条)

于 2013-01-22T01:11:24.393 回答