iis8使用url2.0模块实现http跳转到https

第一步安装,url 2.0重写模块

点击右键选择》获取新的web平台组件

找到url 重写工具2.0并安装

 

找到相应网站,选择 >url重写

 

设定名称后 匹配URL用于路径匹配 通用 (.*)正则匹配所有路径

 

{HTTP_HOST}用于匹配主机域名,我的网站有泛解析,指定了匹配含有szsczx的域名

 

设定重定向,其中 {R:0}规则用于匹配路径

 

<system.webServer>
         <rewrite>
            <rules>
                <rule name="https" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions logicalGrouping="MatchAny">
                        <add input="{HTTP_HOST}" pattern="^.*?szsczx.*$" />
    </conditions>
  <action type="Redirect" url="https://www.szsczx.com/{R:0}" redirectType="Permanent" />
</rule>
            </rules>
        </rewrite></system.webServer>

  如果不想配置,可以修改下,把这段代码放入web.config中。可以实现用户输入主域名和二级域名直接跳转到https协议的域名地址。

原文地址:https://www.cnblogs.com/fogwang/p/7101629.html