IIS 7.5 URL Rewrite 规则来处理基于用户代理的请求 [英] IIS 7.5 URL Rewrite rule to handle request based on user agent
问题描述
我写了一个规则来根据用户代理重定向请求.该规则设置为将默认请求(非移动)重定向到 Domain1
,并将来自移动设备的请求重定向到移动域 Domain2
.
I have written a rule to redirect request based on user agent. The rule is set to redirect default requests (not mobile) to Domain1
and requests from mobile devices to a mobile domain, Domain2
.
即使在应用移动重定向之后,来自移动的所有请求都被带到Domain1
.
Even after applying the mobile redirect, all requests from mobile are taken to Domain1
.
请参阅下面的重定向规则.谁能告诉我我错过了什么?
See the redirect rule below. Can anyone tell me what I'm missing?
<rewrite>
<rules>
<rule name="Mobile UA redirect" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_USER_AGENT}" pattern="^.*BlackBerry.*$ " />
<add input="{HTTP_USER_AGENT}" pattern=".*Mobile.*Safari" />
</conditions>
<action type="Redirect" url="Domain2" />
</rule>
<rule name="Claritinchallenge to" enabled="true" stopProcessing="true">
<match url="(.*)" />
<action type="Redirect" url="Domain1" appendQueryString="false" />
</rule>
</rules>
</rewrite>
推荐答案
在你的 Mobile UA redirect
规则中,条件逻辑分组是默认的:MatchAll
In your Mobile UA redirect
rule, the conditions logical grouping is the one by default: MatchAll
我认为 HTTP_USER_AGENT
匹配 ^.*BlackBerry.*$
的手机不会也匹配 .*Mobile.*Safari
>.所以需要将逻辑分组改为MatchAny
.
I don't think a phone having a HTTP_USER_AGENT
matching ^.*BlackBerry.*$
will also match .*Mobile.*Safari
. So you need to change the logical grouping to MatchAny
.
你的规则是:
<rule name="Mobile UA redirect" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_USER_AGENT}" pattern="^.*BlackBerry.*$ " />
<add input="{HTTP_USER_AGENT}" pattern=".*Mobile.*Safari" />
</conditions>
<action type="Redirect" url="MobileURL" />
</rule>
这篇关于IIS 7.5 URL Rewrite 规则来处理基于用户代理的请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!