在IIS服务器上安装SSL证书后需要把http重定向301到https,不带www重定向301到www才能算是完成任务,那么该怎么做呢?
1、在iis中新建一个网站,把 不带 域名.com 和 www.域名.com域名绑定到该网站。
2、在该网站下创建index.html 和web.config文件
3、把下方iis重定向代码添加到 web.config文件中即可完成http重定向301到https,不带www重定向301到www。
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="www" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^您的域名\.com\.cn$" />
</conditions>
<action type="Redirect" url="https://www.您的域名.com.cn/{R:0}" />
</rule>
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
注:https域名再另一个网站中绑定,具体的 iis添加ssl证书的方法可以访问 https://blog.csdn.net/qq_39339179/article/details/126382855