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已经出现了,以下图所示html

  第二步咱们就能够开始设置跳转了,好比把a.com跳到www.a.com,在a网站的根目录下有一个web.config文件,这个就是设置跳转规则的文件web

<?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.combash

<?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规则,整合代码以下服务器

<?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网站

相关文章
相关标签/搜索