在web.config路径下的system.webserver标签下添加
移动端:注意negate为否定
<rewrite> <rules> <rule name="http-https" stopProcessing="true"> <match url="(.*)" /> <conditions> <add input="{HTTPS}" pattern="^OFF$" /> </conditions> <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" /> </rule> <rule name="UserAgentRedirect" stopProcessing="true"> <match url="^(.*)$" /> <conditions> <add input="{HTTP_USER_AGENT}" pattern=".*Android.*Mobile|.*iPhone.*Mobile|.*Windows Phone.*Mobile" negate="true"/> </conditions> <action type="Redirect" url="https://www.xxx.cn/{R:1}" /> </rule> </rules> </rewrite>
PC端:
<rewrite> <rules> <rule name="http-https" stopProcessing="true"> <match url="(.*)" /> <conditions> <add input="{HTTPS}" pattern="^OFF$" /> </conditions> <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" /> </rule> <rule name="rewirte-www" stopProcessing="true"> <match url="(.*)" /> <conditions> <add input="{HTTP_HOST}" pattern="^(shebao100.cn)" /> </conditions> <action type="Redirect" url="https://www.{HTTP_HOST}/{R:1}" /> </rule> <rule name="UserAgentRedirect" stopProcessing="true"> <match url="^(.*)$" /> <conditions> <add input="{HTTP_USER_AGENT}" pattern=".*Android.*Mobile|.*iPhone.*Mobile|.*Windows Phone.*Mobile" /> </conditions> <action type="Redirect" url="https://m.xxx.cn/{R:1}" /> </rule> </rules> </rewrite>