gpt4 book ai didi

asp.net - 基于多个(但不是全部)条件的 IIS 重定向规则

转载 作者:行者123 更新时间:2023-12-02 10:47:46 25 4
gpt4 key购买 nike

我有一个重写,设置为处理多个不同的用户代理,并且我希望能够在其中任何一个上匹配我的规则。但是,任何与其中一条规则匹配的 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>

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

最佳答案

像下面这样的东西放在底部怎么样:

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

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

关于asp.net - 基于多个(但不是全部)条件的 IIS 重定向规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14320187/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com