分享

IIS7的http 做301重定向到https

 陕南赤子 2019-05-23

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


http跳转到https

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

<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域名, 注意,要放在<rules>和</rules>之间。

<rule name="www" stopProcessing="true">
                    <match url=".*" />
                    <conditions>
                        <add input="{HTTP_HOST}" pattern="^ip110\.com$" />
                    </conditions>
                    <action type="Redirect" url="https://www./{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="^ip110\.com$" />
                    </conditions>
                    <action type="Redirect" url="https://www./{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>

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多