[英]Redirect to mobile default page by UrlRewrite module on IIS
假設有兩個設計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>
但它被困在太多請求中
yourSite將您重定向了太多次。
顯然是由於該rule
,它可以mobile.html
重定向到mobile.html
,但是通過再次使mobile.html
再次mobile.html
該操作,它將以循環重定向的方式刪除。 同樣通過添加<add input="{url}" negate="true" pattern="mobile.html"/>
也不起作用。
您可以嘗試以下方法。 添加另一個條件,該條件不包含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>
如果我沒有理解你的問題,你希望誰在陸地上移動用戶desktop.html
重定向到mobile.html
和誰在陸地上桌面用戶mobile.html
重定向到desktop.html
。 這將需要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>
請注意,這2條規則依賴於永遠不會100%可靠的用戶代理 (因為它們可以更改)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.