Windows IIS 强制 HTTPS
2025年3月16日小于 1 分钟
Windows IIS 强制 HTTPS
准备工作
- 确保已安装 IIS URL Rewrite Module
- SSL 证书已正确安装
- 验证证书状态正常
配置步骤
安装 URL Rewrite 模块
下载并安装 IIS URL Rewrite Module
2008系统点击下载
2012以上版本系统点击下载配置重定向规则
打开站点根目录下的 web.config 文件(如果没有则新建一个)
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <rewrite> <rules> <rule name="HTTP to HTTPS redirect" stopProcessing="true"> <match url="(.*)" /> <conditions> <add input="{HTTPS}" pattern="off" ignoreCase="true" /> </conditions> <action type="Redirect" redirectType="Permanent" url="https://{HTTP_HOST}/{R:1}" /> </rule> </rules> </rewrite> </system.webServer> </configuration>
验证配置
- 使用 HTTP 访问网站
- 确认是否自动跳转到 HTTPS
- 检查跳转是否正常
常见问题
跳转不生效
- 检查 URL 重写模块是否正确安装
- 验证重定向规则是否正确
- 确认 IIS 服务是否重启
循环跳转
- 检查 SSL 证书配置
- 验证重定向规则
- 查看服务器错误日志