欢迎来到资源库(www.zyku.net)

IIS

当前位置:首页 > 服务器教程 > IIS > IIS

IIS7 IIS 7.5下http 做301重定向到https

时间:2020-04-01|栏目:IIS|点击:|我要投稿

我们的服务器部分是windows下的IIS平台,一些用户安装了SSL https证书后,不会控制301跳转,下面直接贴出代码,根据需要把代码放到web.config文件里即可。

http跳转到https

这个代码段是http重定向到https, 注意,要放在和之间。

<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>

http跳转到https

提醒:里面的网址记得改成你自己的网站,别懒得只会copy!

这个代码段是无3w重定向到有3w域名, 注意,要放在和之间。

<rule name="www" stopProcessing="true">
       <match url=".*" />
       <conditions>
       <add input="{HTTP_HOST}" pattern="^domain\.com$" />
       </conditions>
       <action type="Redirect" url="https://www.domain.com/{R:0}" />
 </rule>

完整的web.config代码

下面代码包含了,无3w网址,跳转到有3w网址; 以及, http全部跳转到https

当然了,知道大家懒,已经将两份整合到一起,将下面全部代码保存成web.config文件,存放到空间的web目录下即可。再次提醒:里面的网址记得改成你自己的网站,别懒得只会copy!

<?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="^domain\.com$" />
                    </conditions>
                    <action type="Redirect" url="https://www.domain.com/{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://www.ip110.com/faq/technique/1061.shtml

(资源库 www.zyku.net)

关于我们 | 版权申明 | 寻求合作 |

重要申明:本站所有的文章、图片、评论等内容,均由网友发表或上传并维护或收集自网络,仅供个人学习交流使用,版权归原作者所有。

如有侵犯您的版权,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:95148658 | 邮箱:mb8#qq.com(#换成@)

苏ICP备2020066115号-1

本网站由提供CDN加速/云存储服务