IIS 7.5 URL重写规则,用于根据用户代理处理请求 [英] IIS 7.5 URL Rewrite rule to handle request based on user agent

查看:513
本文介绍了IIS 7.5 URL重写规则,用于根据用户代理处理请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已根据用户代理编写了重定向请求的规则。

I have wrote a rule to redirect request based on user agent.

规则设置为将默认请求(非移动设备)重定向到 Domain1 以及从移动设备到移动域的请求 Domain2

The rule is set to redirect default requests(not mobile) to Domain1 and requests from mobile to mobile domain Domain2.

目前即使应用了移动设备将来自移动设备的所有请求重定向到 Domain1
找到下面的重定向规则。谁能告诉我我缺少什么?

Currently even after applying mobile redirect all request from mobile are taken to Domain1 Find 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="MobileURL" />
                </rule>
                <rule name="Claritinchallenge to" enabled="true" stopProcessing="true">
                    <match url="(.*)" />
                    <action type="Redirect" url="Second Domain" appendQueryString="false" />
                    <conditions>
                    </conditions>
                </rule>
            </rules>
        </rewrite>


推荐答案

移动UA重定向中规则,条件逻辑分组是默认值: MatchAll

In your Mobile UA redirect rule, the conditions logical grouping is the one by default: MatchAll

我不知道我认为匹配 ^。* BlackBerry。* $ HTTP_USER_AGENT 的手机也会匹配。*移动。* 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重写规则,用于根据用户代理处理请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆