IIS 7.5 URL Rewrite rule to handle request based on user agent

时光总嘲笑我的痴心妄想 提交于 2019-12-06 04:36:21

问题


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 to mobile domain Domain2.

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>

回答1:


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

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.

You rule would then be:

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


来源:https://stackoverflow.com/questions/15904482/iis-7-5-url-rewrite-rule-to-handle-request-based-on-user-agent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!