zoukankan      html  css  js  c++  java
  • 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>
  • 相关阅读:
    时间序列数据库(TSDB)初识与选择(InfluxDB、OpenTSDB、Druid、Elasticsearch对比)
    Prometheus COMPARISON TO ALTERNATIVES
    认真分析mmap:是什么 为什么 怎么用
    Flume学习之路 (二)Flume的Source类型
    Flume学习之路 (一)Flume的基础介绍
    Spark学习之路 (二十一)SparkSQL的开窗函数和DataSet
    Spark学习之路 (二十)SparkSQL的元数据
    CentOS 7的安装
    Spark学习之路 (十九)SparkSQL的自定义函数UDF
    Spark学习之路 (十八)SparkSQL简单使用
  • 原文地址:https://www.cnblogs.com/fuqiang88/p/6080000.html
Copyright © 2011-2022 走看看