gpt4 book ai didi

asp.net - 将规则重写为 WWW,除非在本地主机上

转载 作者:行者123 更新时间:2023-12-05 09:23:10 24 4
gpt4 key购买 nike

出于 SEO 优化的原因,我将对 http://Example.com 的所有请求都重定向到 http://www.Example.com。问题是在本地工作时,对 localhost 的请求也会被重定向。

我尝试了这个 Rewrite rule to HTTPS except when on localhost 中的建议没有运气就回答。

这是我在 Web.Config 中的实际重定向规则(希望它可以帮助正在寻找 WWW 重写规则的人):

  <system.webServer>
<rewrite>
<rules>
<rule name="redirect example.com to www.example.com">
<match url="^(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.example\.com$" negate="true" />
</conditions>
<action type="Redirect" url="http://www.example.com/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>

有什么帮助吗?

最佳答案

你可以按如下方式做一个规则

<rule name="redirect example.com to www.example.com">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="^www.*" negate="true" />
<add input="{HTTP_HOST}" pattern="localhost" negate="true" />
</conditions>
<action type="Redirect" url="http://www.example.com/{R:0}" />
</rule>
</rules>

它将两个条件与“MatchAll”组合在一起,其中第一个输入类似于您已有的输入(如果需要,您可以使用您的输入),第二个输入是检查本地主机。请注意,您可能需要使用 {R:0} 并且我还将匹配 url 更改为 .*

您还可以使用不同的 web.configs(调试和发布)。在这里阅读更多:http://msdn.microsoft.com/en-us/library/vstudio/dd465318(v=vs.100).aspx

关于asp.net - 将规则重写为 WWW,除非在本地主机上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24016236/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com