IIS7 / IIS7.5 URL 重写 HTTP 重定向到 HTTPS

4 篇文章 0 订阅


1、购买SSL证书,参考:http://www.cnblogs.com/yipu/p/3722135.html

2、IIS7 / IIS 7.5 下绑定 HTTPS 网站(购买Wildcard SSL泛域名证书可绑定多个子域名)参考上文

3、下载安装URL重写模块:Microsoft URL Rewrite Module

32位:http://download.microsoft.com/download/4/9/C/49CD28DB-4AA6-4A51-9437-AA001221F606/rewrite_x86_zh-CN.msi

64位:http://download.microsoft.com/download/4/E/7/4E7ECE9A-DF55-4F90-A354-B497072BDE0A/rewrite_x64_zh-CN.msi

4、取消勾选“SSL设置”-》“要求 SSL”


5、ASP.NET站可直接修改web.config(与“6、IIS配置图示”效果相同),例如:见<rewrite>...</rewrite>节点

复制代码

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <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>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

复制代码

配置项说明

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="HostNameRule1">
                    <match url="(.*)" />
                    <!--匹配所有条件-->
                    <conditions logicalGrouping="MatchAny">
                        <!--当不是使用https协议访问的时候-->
                        <add input="{HTTPS}" pattern="^OFF$" />
                        <!--并且访问的host不是xxx.com这种,例如www.xxx.com-->
                        <add input="{HTTP_HOST}" pattern="^xxx\.com$" negate="true" />
                    </conditions>
                    <!--跳转到https-->
                    <action type="Redirect" url="https://xxx.com/{R:1}" />
                </rule>
                <rule name="HTTPS redirect">
                    <match url="(.*)" />
                    <conditions>
                        <!--当使用HTTPS协议访问-->
                        <add input="{HTTPS}" pattern="^ON$" />
                        <!--当访问 https://www.xxx.com的时候 -->
                        <add input="{HTTP_HOST}" pattern="^xxx\.com$" negate="true" />
                    </conditions>
                    <!--跳转到HTTPS-->
                    <action type="Redirect" url="https://xxx.com/{R:1}" redirectType="SeeOther" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

6、IIS配置图示(图形化的操作过程,与上步效果相同,适用于asp/php等站)

选择要配置的网站,如:,找到“URL重写”,没有的话看上面第3步


进入“URL重写”模块,点击“添加规则”


选择“空白规则”


名称:HTTP to HTTPS redirect

模式:(.*)



条件输入:{HTTP}

模式:off 或 ^OFF$

 或 

重定向URL:https://{HTTP_HOST}/{R:1}

重定向类型:已找到(302) 或 参阅其它(303)

配置完成后“应用”到当前站点:


URL重写配置结果:


至此配置完成


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值