最近客户一个网站升级至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>

最新文章

  1. Eclipse Java注释模板设置详解
  2. 关于ASPXGridview的双击事件弹出 【转】
  3. C语言32个关键字
  4. FZU 2195 思维
  5. Makefile的规则
  6. 两天来学习C的感受
  7. ios8新特性widget开发-b
  8. linux上 安装并 运行opencv
  9. Hibernate介绍和入门案例
  10. HDU 4451 Dressing
  11. URL重定向
  12. php中的冒泡排序算法
  13. net 将手机号码中间的数字替换成星号
  14. Ubuntu下OpenGL开发环境的搭建
  15. Linux内存管理 (13)回收页面
  16. Mysql IN语句查询
  17. 第十一周(11.24-12.01)----WBS功能分解
  18. linux tcpdump 抓包
  19. 从头认识java-特辑-你不知道的main函数
  20. Shellinabox安装及使用教程

热门文章

  1. opcode修改
  2. Web安全检测工具的使用.
  3. 破解JS加密:url unicode加密而已
  4. 引入bootstrap
  5. fsck害了我很久了,必须关掉,因为他每次打卡都要推迟数十分钟。
  6. CodeForces 610D Vika and Segments
  7. 17.4.3 使用MulticastSocket实现多点广播(3)
  8. Delphi XE7 Update1 下载破解、带源码和帮助安装序列号
  9. php 中的魔术方法-----“事件方法”
  10. css01