iis7设置http跳转https实测可用
前面ytkah和大家聊了Apache设置http如何301到https,现在我们说说iis7设置http跳转https,因为还是有很多人在用iis服务器。首先要先安装url rewrite module,到这里去下载http://www.microsoft.com/en-us/download/details.aspx?id=7435,以administrator管理员的身份去安装这个模块,安装完以后需要重启一下IIS,你就会看到URL Rewrite已经出现了,如下图所示
第二步我们就可以开始设置跳转了,比如把a.com跳到www.a.com,在a网站的根目录下有一个web.config文件,这个就是设置跳转规则的文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <?xml version= "1.0" encoding= "UTF-8" ?> <configuration> <system.webServer> <rewrite> <rules> <rule name= "WWW Redirect" stopProcessing= "true" > <match url= ".*" /> <conditions> <add input= "{HTTP_HOST}" pattern= "^a.com$" /> < /conditions > <action type = "Redirect" url= "http://www.a.com/{R:0}" redirectType= "Permanent" /> < /rule > < /rules > < /rewrite > < /system .webServer> < /configuration > |
如果要把b.com跳到www.a.com
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <?xml version= "1.0" encoding= "UTF-8" ?> <configuration> <system.webServer> <rewrite> <rules> <rule name= "WWW Redirect" stopProcessing= "true" > <match url= ".*" /> <conditions> <add input= "{HTTP_HOST}" pattern= "^b.com$" /> < /conditions > <action type = "Redirect" url= "http://www.a.com/{R:0}" redirectType= "Permanent" /> < /rule > < /rules > < /rewrite > < /system .webServer> < /configuration > |
重点来了,如果有多个站点(包含www.a.com),并且这些站点都要跳转到https://www.a.com,要如何操作呢?首先多站点用|线分割,http跳https需要另外设定一个rule规则,整合代码如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | <?xml version= "1.0" encoding= "UTF-8" ?> <configuration> <system.webServer> <rewrite> <rules> <rule name= "WWW Redirect" stopProcessing= "true" > <match url= ".*" /> <conditions> <add input= "{HTTP_HOST}" pattern= "^a.com|b.com$" /> < /conditions > <action type = "Redirect" url= "https://www.a.com/{R:0}" redirectType= "Permanent" /> < /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://www.a.com" /> < /rule > < /rules > < /rewrite > < /system .webServer> < /configuration > |
以上算比较完美的解决方案了,不明白的可以联系ytkah

加微信交流
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
2015-05-09 网页出现scanstyles does nothing in Webkit / Mozilla的解决方法
2014-05-09 在iphone上安装多个微信 【微信营销必备】