在 IIS 中配置 HTTPS 重定向的资料在中文网站上不是很多,在此给出 web.config 的一个示例。
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <defaultDocument> <!-- ... --> </defaultDocument> <rewrite> <rules> <rule name="ENFORCE_HTTPS" enabled="true" stopProcessing="true"> <match url="(.*)" /> <conditions logicalGrouping="MatchAny"> <add input="{HTTPS}" pattern="OFF" /> <add input="{SERVER_PORT}" pattern="80" /> </conditions> <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" /> </rule> </rules> </rewrite> </system.webServer> </configuration>
在 IIS 中,rule 的 stopProcessing 这一属性表示的是:如果满足这一规则,则处理完当前规则后不处理其他规则。
在 IIS 上部署 HTTPS 也并不是特别麻烦,使用 Certify 能很方便地在图形化界面下部署基于 Let’s Encrypt 的免费 SSL 证书。