【摸鱼教程】IIS HTTP重定向到HTTPS

版权声明:关注微信公众号:摸鱼科技资讯,联系我们 https://blog.csdn.net/qq_36949176/article/details/82821010

网站升级至HTTPS协议访问,为了用户输入,要求当用户输入的是HTTP协议时,能自动定向到HTTPS,类似摸鱼科技官方网站,当你输入 moyu.studiosworks.com并回车后,地址栏自动变成了https://moyu.studiosworks.cn

HTTPS(全称:Hyper Text Transfer Protocol over Secure Socket Layer),是以安全为目标的HTTP通道,简单讲是HTTP的安全版。即HTTP下加入SSL层,HTTPS的安全基础是SSL,因此加密的详细内容就需要SSL。 它是一个URI scheme(抽象标识符体系),句法类同http:体系。用于安全的HTTP数据传输。https:URL表明它使用了HTTP,但HTTPS存在不同于HTTP的默认端口及一个加密/身份验证层(在HTTP与TCP之间)。这个系统的最初研发由网景公司(Netscape)进行,并内置于其浏览器Netscape Navigator中,提供了身份验证与加密通讯方法。现在它被广泛用于万维网上安全敏感的通讯,例如交易支付方面。

以前步骤简要介绍了如何实现该功能。 1)下载并安装Microsoft URL 重写模块 https://www.microsoft.com/zh-CN/download/details.aspx?id=7435 备注:根据不同的系统,不同的语言选择。 我的机器是英文版的,所以以下截图基本都为英文。 2) 站点绑定以下两种协议:

注意:默认的https端口号为443, 因为我本机这个端口已经被利用,所以此处以449演示。

3)站点的SSL设置,确保“Require SSL”未选中。

 3)如果是ASP.NET站点,则直接在Web.config文件中添加以下配置节,作为<configuration>的子元素放在文件末尾即可。


<system.webServer>

        <rewrite>

            <rules>

                <rule name="Redirect to https" stopProcessing="true">

                    <match url="(.*)" />

                    <conditions>

                        <add input="{HTTPS}" pattern="^OFF$" />

                        <add input="{HTTPS_HOST}" pattern="^(localhost)" negate="true" />

                    </conditions>

                    <action type="Redirect" url="https://{HTTP_HOST}:449/{R:1}" redirectType="SeeOther" />

                </rule>

            </rules>

        </rewrite>

    </system.webServer>



注意:当你使用默认HTTPS端口时,上面的端口号449就不需要了,直接为https://{HTTP_HOST}/{R:1}



上面的配置也可以直接在IIS中的URL Write中手动添加,完成后大致如下:

扫描二维码关注公众号,回复: 3463006 查看本文章

Web.config配置:

<?xml version="1.0" encoding="utf-8"?>

<!--
  有关如何配置 ASP.NET 应用程序的详细信息,请访问
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->

<configuration>

    <system.web>
      <compilation debug="true" targetFramework="4.5" />
      <httpRuntime targetFramework="4.5" />
    </system.web>

<system.webServer>
        <rewrite>
            <rules>
                <rule name="Redirect to https" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{HTTPS}" pattern="^OFF$" />
                        <add input="{HTTPS_HOST}" pattern="^(localhost)" negate="true" />
                    </conditions>
                    <action type="Redirect" url="https://{HTTP_HOST}:449/{R:1}" redirectType="SeeOther" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

更多文章、相关资料等关注微信公众号:摸鱼科技资讯。或者点击链接:http://mp.weixin.qq.com/mp/homepage?__biz=MzU5MjY1ODg0NA==&hid=3&sn=c8b9f858ce938d785e3f799a8cb59574&scene=18#wechat_redirect 

猜你喜欢

转载自blog.csdn.net/qq_36949176/article/details/82821010