我在IIS 8.0上安装了URL重写模块并配置了规则
以下是规则
<appcmd>
<CONFIG CONFIG.SECTION="system.webServer/rewrite/globalRules" path="MACHINE/WEBROOT/APPHOST" overrideMode="Inherit" locked="false">
<system.webServer-rewrite-globalRules>
<rule name="Mobile Redirect" enabled="true" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^$" ignoreCase="true" />
<conditions logicalGrouping="MatchAny" trackAllCaptures="false">
<add input="{HTTP_USER_AGENT}" pattern="android|blackberry|googlebot-mobile|iemobile|iphone|ipod|opera mobile|palmos|webos" />
<add input="{HTTP_X-Device-User-Agent}" pattern="midp|mobile|phone" />
<add input="{HTTP_X-OperaMini-Phone-UA}" pattern="midp|mobile|phone" />
</conditions>
<serverVariables>
</serverVariables>
<action type="Redirect" url="/en-mobile" appendQueryString="false" />
</rule>
<rule name="Add HTTPS and WWW prefix to website.COM" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTPS}" pattern="^OFF$" />
<add input="{HTTP_HOST}" pattern="^website\.com" />
</conditions>
<serverVariables>
</serverVariables>
<action type="Redirect" url="https://www.website.com/{R:1}" appendQueryString="false" />
</rule>
<rule name="Add HTTPS to WWW.website.COM" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTPS}" pattern="^OFF$" />
<add input="{HTTP_HOST}" pattern="^www\.(.+)$" />
</conditions>
<serverVariables>
</serverVariables>
<action type="Redirect" url="https://www.website.com/{R:1}" />
</rule>
</system.webServer-rewrite-globalRules>
</CONFIG>
</appcmd>
在上述第一条规则中,移动重定向是在用户来自移动浏览器时完成的。我重定向到https://www.website.com/en-mobile
但是当我喜欢这个https://m.website.com/en-mobile
时,它会出错,但是当我手动浏览它时效果非常好。因此,当人们从https://www.website.com转到https://m.website.com/en-mobile