从www重定向到nonewww不工作



该应用程序构建在asp.net内核3.1上,并进行react。他们是同源的

web.config中,从http重定向到https正在工作

web.config中,从www.example.comexample.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.example.com进入重定向循环并显示ERR_TOO_MANY_REDIRECTS
  • 在Postman中,错误为Error: Exceeded maxRedirects. Probably stuck in a redirect loop https://www.example.com/

您可以尝试此规则从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>

最新更新