简体   繁体   English

带有“ nomobile” cookie的移动设备的IIS URL重写规则

[英]IIS URL Rewrite rule for mobile with “nomobile” cookie

We are using IIS URL Rewrite module to redirect all request from a mobile browser to m.mymobilesite.com by checking HTTP_USER_AGENT. 我们正在使用IIS URL重写模块通过检查HTTP_USER_AGENT将所有请求从移动浏览器重定向到m.mymobilesite.com。 This works fine and now we need to implement a "View Full Site" link which will allow the user to see the main site. 这可以正常工作,现在我们需要实现一个“查看完整站点”链接,该链接将允许用户查看主站点。 Trying to achieve this by adding a "nomobile" cookie when user clicks on "View Full Site" link which will be validated and negated by the rule. 尝试通过在用户单击“查看完整站点”链接时添加“ nomobile” cookie来实现此目的,该链接将由规则进行验证和否定。 For some reason my rule doesn't seems to work. 由于某些原因,我的规则似乎不起作用。

Please help. 请帮忙。

<rewrite>
<rules>
    <rule name="MobileRedirect" patternSyntax="ECMAScript" stopProcessing="true">    
        <match url=".*" ignoreCase="true" />
        <conditions logicalGrouping="MatchAll">
            <add input="{HTTP_COOKIE}" pattern="nomobile" ignoreCase="true" negate="true" />
            <add input="{HTTP_USER_AGENT}" pattern="android|blackberry|googlebot-mobile|iemobile|iphone|ipod|opera mobile|palmos|webos" />
        </conditions>    
        <action type="Redirect" url="http://m.mymobilesite.com" appendQueryString="false" redirectType="Found" />
    </rule>
</rules> </rewrite>

The rule is perfect and I figured out the issue after doing a trace on failed request at IIS level as described here 规则是完美的,我所描述的对失败的请求在IIS级别执行跟踪后想通了这个问题在这里

The cookie which I was creating while user select the "View Full Site" link was not created with the domain name. 我在用户选择“查看完整站点”链接时创建的cookie没有使用域名创建。 I added domain="mymainsite.com" on the cookie creation script and it is working fine now. 我在cookie创建脚本上添加了domain =“ mymainsite.com”,现在可以正常工作了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM