首页 > 解决方案 > URL 具有 HTTPS 时的 Web 配置重定向

问题描述

我想尝试从

"https://abcd.net-------------> https://www.abcd.net"

我已经重定向了

"http://abcd.net-------------> http://www.abcd.net"
"http://www.abcd.net-------------> https://www.abcd.net"




<rule name="Force HTTPS" enabled="true" stopProcessing="true">
    <match url="(.*)" />
        <conditions logicalGrouping="MatchAll">
            <add input="{HTTPS}" negate="true" pattern="^ON$" />
                </conditions>
    <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" appendQueryString="false" redirectType="Permanent" />
</rule>

需要使用 www 将所有 abcd.net 重定向到 HTTPS

标签: .netredirectiisurl-rewritingweb-config

解决方案


根据您的描述,我建议您可以尝试添加一个新的 url 重写规则以匹配“ https://abcd.net ”以重定向到“ https://www.abcd.net ”。

细节,你可以参考下面的重写规则:

  <rule name="Redirect https" enabled="true" stopProcessing="true">
    <match url="(.*)" />
    <conditions logicalGrouping="MatchAll">
      <add input="{HTTPS}"   pattern="^ON$" />
      <add input="{HTTP_HOST}" pattern="abcd.net" />
    </conditions>
    <action type="Redirect" url="https://www.abcd.net/{R:0}" appendQueryString="false" redirectType="Permanent" />
  </rule>
  <rule name="Force HTTPS" enabled="true" stopProcessing="true">
    <match url="(.*)" />
    <conditions logicalGrouping="MatchAll">
      <add input="{HTTPS}" negate="true" pattern="^ON$" />
    </conditions>
    <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" appendQueryString="false" redirectType="Permanent" />
  </rule>

推荐阅读