• IIS HTTP重定向到HTTPS


    最近客户一个网站升级至HTTPS协议访问,但是为了用户输入,客户要求当用户输入的是HTTP协议时,能自动定向到HTTPS,类似百度网站,当你输入www.baidu.com并回车后,地址栏自动变成了https://www.baidu.com。

    以前步骤简要介绍了如何实现该功能。

    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中手动添加,完成后大致如下:

    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>
  • 相关阅读:
    Tarjan 算法 自学整理
    POJ 2395 Out of Hay
    Codevs 1557 热浪
    Codevs 2956 排队问题
    Codevs 1005 生日礼物
    集合
    奇怪的函数
    关押罪犯
    搭积木
    大数据
  • 原文地址:https://www.cnblogs.com/fuqiang88/p/6080000.html
Copyright © 2020-2023  润新知