Asp.net 将规则重写为WWW,但在本地主机上时除外
出于SEO优化的原因,我将所有请求发送到Asp.net 将规则重写为WWW,但在本地主机上时除外,asp.net,url-rewriting,web-config,Asp.net,Url Rewriting,Web Config,出于SEO优化的原因,我将所有请求发送到http://Example.com重定向到http://www.Example.com。问题是,在本地工作时,对localhost的请求也会被重定向 我尝试了这个答案中的建议,但没有成功 下面是我在Web.Config中的实际重定向规则(希望它能帮助那些正在寻找将规则重写到WWW的人): 有什么帮助吗?您可以按如下规则操作 <rule name="redirect example.com to www.example.com"> &
http://Example.com
重定向到http://www.Example.com
。问题是,在本地工作时,对localhost
的请求也会被重定向
我尝试了这个答案中的建议,但没有成功
下面是我在Web.Config
中的实际重定向规则(希望它能帮助那些正在寻找将规则重写到WWW的人):
有什么帮助吗?您可以按如下规则操作
<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>
我想保留一个更智能的web.config,它不太容易出错。不幸的是,您的解决方案不起作用,localhost:3064仍然被重定向到www.example.com
<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>