[英]Redirect to mobile default page by UrlRewrite module on IIS
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
假设有两个设计
mobile.html
页面,一个用于桌面,名为mobile.html
,另一个是desktop.html
,通过UrlRewrite
下面的命令,我可以将用户重定向到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.
yourSite将您重定向了太多次。
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. 显然是由于该
rule
,它可以mobile.html
重定向到mobile.html
,但是通过再次使mobile.html
再次mobile.html
该操作,它将以循环重定向的方式删除。 also by adding <add input="{url}" negate="true" pattern="mobile.html"/>
it is not working. 同样通过添加
<add input="{url}" negate="true" pattern="mobile.html"/>
也不起作用。
You can try the following. 您可以尝试以下方法。 Add another condition that excludes the mobile.html url.
添加另一个条件,该条件不包含mobile.html网址。
<rule name="MobileRedirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_USER_AGENT}" pattern="midp|mobile|phone|android|iphone|ipad" />
<add input="{PATH_INFO}" pattern="^/mobile.html$" negate="true"/>
</conditions>
<action type="Redirect" url="/mobile.html" />
</rule>
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
. 如果我没有理解你的问题,你希望谁在陆地上移动用户
desktop.html
重定向到mobile.html
和谁在陆地上桌面用户mobile.html
重定向到desktop.html
。 That would require 2 rules as follow: 这将需要2条规则,如下所示:
<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>
Note that this 2 rules rely on user agent which are never 100% reliable (since they can be changed). 请注意,这2条规则依赖于永远不会100%可靠的用户代理 (因为它们可以更改)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.