IIS 配置web.config 实现http重定向跳转HTTPS,包括不带www跳转到带www

web.config实现http重定向跳转HTTPS,代码如下:

        <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>

web.config重定向带www的域名转向www域名规则,代码如下

                <rule name="不带www转向www域名规则" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{HTTP_HOST}" pattern="^xmjdwx.cc$" ignoreCase="false" />
                    </conditions>
                    <action type="Redirect" url="https://www.xmjdwx.cc{R:1}" redirectType="Found" />
                </rule>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
     <!--http转https-->
        <rule name="Redirect to https" stopProcessing="true">
          <match url="(.*)" />
          <conditions>
            <add input="{HTTPS}" pattern="^OFF$" />
          </conditions>
          <action type="Redirect" url="https://{HTTP_HOST}:443/{R:1}" redirectType="SeeOther" />
        </rule>
        <!--将带www转为不带www-->
        <rule name="WWW Redirect" stopProcessing="true">
          <match url=".*" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^www.xxx.com$"/>
          </conditions>
          <action type="Redirect" url="https://xxx.com/{R:0}" redirectType="Permanent" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

 

© 版权声明
THE END
喜欢就支持一下吧
点赞0
分享
评论 抢沙发

请登录后发表评论