通过IIS上的UrlRewrite模块重定向到移动默认页面 [英] Redirect to mobile default page by UrlRewrite module on IIS

查看:91
本文介绍了通过IIS上的UrlRewrite模块重定向到移动默认页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设有两个设计页面,一个页面名为 mobile.html ,而另一个页面为 desktop.html ,通过下面的 UrlRewrite ,我可以将用户重定向到 mobile.html

Suppose there are two designed pages, one for desktop named mobile.html and the other one is desktop.html, by below UrlRewrite I am able to redirect user to mobile.html

<rewrite>
      <rules>
            <rule name="MobileRedirect" stopProcessing="true">
                <match url=".*" />
                <conditions>
                    <add input="{HTTP_USER_AGENT}" pattern="midp|mobile|phone|android|iphone|ipad" />
                </conditions>
                <action type="Redirect" url="/mobile.html" />
            </rule>
      </rules>
</rewrite>

但是它被困在太多请求中

but it trapped in Too Many Request

您的网站将您重定向了太多次.

yourSite redirected you too many times.

很明显是因为该 rule ,它将毫无问题地重定向到 mobile.html ,但只需获取 mobile.html 该动作再次发生,它将以循环重定向的方式丢弃.也可以通过添加< add input ="{url}" negate ="true" pattern ="mobile.html"/> 来实现.

it is clear that is because of that rule, it will redirected to mobile.html with no problem but by getting mobile.html that action occurred again, it will dropped in loop redirection. also by adding <add input="{url}" negate="true" pattern="mobile.html"/> it is not working.

推荐答案

如果我正确理解了您的问题,则希望将 desktop.html 上的移动用户重定向到 mobile.html 和登陆到 mobile.html 上的桌面用户将被重定向到 desktop.html .这将需要2条规则,如下所示:

If I understand your problem correctly, you want mobile users who land on desktop.html to be redirected to mobile.html and desktop users who land on mobile.html to be redirected to desktop.html. That would require 2 rules as follow:

<rewrite>
      <rules>
            <rule name="MobileRedirect" stopProcessing="true">
                <match url="desktop.html" />
                <conditions>
                    <add input="{HTTP_USER_AGENT}" pattern="midp|mobile|phone|android|iphone|ipad" />
                </conditions>
                <action type="Redirect" url="/mobile.html" />
            </rule>
            <rule name="DesktopRedirect" stopProcessing="true">
                <match url="mobile.html" />
                <conditions>
                    <add input="{HTTP_USER_AGENT}" pattern="midp|mobile|phone|android|iphone|ipad" negate="true" />
                </conditions>
                <action type="Redirect" url="/desktop.html" />
            </rule>
      </rules>
</rewrite>

请注意,这2条规则依赖于用户代理,它们从来都不是100%可靠的(因为可以更改).

Note that this 2 rules rely on user agent which are never 100% reliable (since they can be changed).

这篇关于通过IIS上的UrlRewrite模块重定向到移动默认页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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