【问题标题】:How to redirect non WWW to WWW in web.config如何在 web.config 中将非 WWW 重定向到 WWW
【发布时间】:2018-12-08 00:09:33
【问题描述】:

我在这里试过web.config redirect non-www to www

并尝试过:

<rule name="ensurewww" enabled="false" stopProcessing="true">
    <match url=".*" />
    <conditions>
         <add input="{CACHE_URL}" pattern="^(.+)://(?!www)(.*)" />
    </conditions>
    <action type="Redirect" url="{C:1}://www.{C:2}/{R:1}" redirectType="Permanent" />
</rule>

结果:1​​.abc.com ---> www.abc.com

结果2.abc.com/a.aspx--->www.abc.com/a.aspx 错误

结果 3.abc/com/abc---->www.abc.com/abc

最后:我想结果 2 和结果 3 为真

【问题讨论】:

    标签: c# web iis web-config url-redirection


    【解决方案1】:

    试过了:IIS Redirect non-www to www AND http to https

    <rule name="Force WWW and SSL" enabled="true" stopProcessing="true">
          <match url="(.*)" />
          <conditions logicalGrouping="MatchAny">
              <add input="{HTTP_HOST}" pattern="^[^www]" />
              <add input="{HTTPS}" pattern="off" />
          </conditions>
          <action type="Redirect" url="https://www.obu.vn/{R:1}" appendQueryString="true" redirectType="Permanent" />
    </rule>
    

    它将非 www 重定向到 www 和 http 到 https

    【讨论】:

      猜你喜欢
      • 2022-03-04
      • 1970-01-01
      • 1970-01-01
      • 2017-12-01
      • 1970-01-01
      • 2017-03-30
      • 2018-06-06
      • 1970-01-01
      相关资源
      最近更新 更多