1:在根目录web.config加入以下代码
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="http redirect to https" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
<add input="{HTTPS_HOST}" pattern="^(localhost)" negate="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>2:IIS管理器内该网站的 SSL设置,“要求SSL”一定不要勾选,客户证书选择忽略!不然会造成 http 403 或者 500 错误,无法跳转 https。百度就会抓取失败。
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="HostNameRule1">
<match url="(.*)" />
<!–匹配所有条件–>
<conditions logicalGrouping="MatchAny">
<!–当不是使用https协议访问的时候–>
<add input="{HTTPS}" pattern="^OFF$" />
<!–并且访问的host不是9416.cn这种,例如www.9416.cn–>
<add input="{HTTP_HOST}" pattern="^www\.9416\.cn$" negate="true" />
</conditions>
<!–跳转到https–>
<action type="Redirect" url="https://www.9416.cn/{R:1}" />
</rule>
<rule name="HTTPS redirect">
<match url="(.*)" />
<conditions>
<!–当使用HTTPS协议访问–>
<add input="{HTTPS}" pattern="^ON$" />
<!–当访问 https://9416.cn的时候 –>
<add input="{HTTP_HOST}" pattern="^www\.9416\.cn$" negate="true" />
</conditions>
<!–跳转到HTTPS–>
<action type="Redirect" url="https://www.9416.cn/{R:1}" redirectType="SeeOther" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>