从 www 重定向到 none-www 不工作

Redirect from www to none-www not working

该应用程序基于 asp.net 核心 3.1 构建并做出反应。他们是同源的。

web.confighttp 重定向到 https working.

web.config中从www.example.com重定向到example.com不工作

        // Piece of my web.config
        <rules>
          <rule name="HTTP to HTTPS redirect" stopProcessing="true">
            <match url="(.*)" />
            <conditions>
              <add input="{HTTPS}" pattern="off" ignoreCase="true" />
            </conditions>
            <action type="Redirect" redirectType="Permanent" url="https://{HTTP_HOST}/{R:1}" />
          </rule>
          <rule name="RedirectWwwToNonWww" stopProcessing="false">
            <match url="(.*)" />
            <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
              <add input="{HTTP_HOST}" pattern="^(www\.)(.*)$" />
            </conditions>
            <action type="Redirect" url="https://{C:2}{REQUEST_URI}" redirectType="Permanent" />
          </rule>
        </rules>

您可以尝试使用此规则从 www 重定向到 none-www:

<rule name="SecureRedirect" stopProcessing="true">
  <match url="^(.*)$" />
    <conditions>
      <add input="{HTTPS}" pattern="off" />
      <add input="{HTTP_HOST}" pattern="^(www\.)?(.*)$" />
    </conditions>
  <action type="Redirect" url="https://{C:2}" redirectType="Permanent" />
</rule>