以下是Web.config中将裸域重定向到www。
的部分<system.webServer>
<rewrite>
<rules>
<clear/>
<rule name="WWW Rewrite" enabled="true">
<match url="(.*)"/>
<conditions>
<add input="{HTTP_HOST}" negate="true" pattern="^www\."/>
</conditions>
<action type="Redirect" url="http://www.{HTTP_HOST}/{R:0}" appendQueryString="true" redirectType="Permanent"/>
</rule>
</rules>
</rewrite>
</system.webServer>
问题是在任何其他地址前加上“www”,例如:
我需要它只重定向mysite.com而不是别的。如何修复规则?
答案 0 :(得分:3)
我认为你过分思考它。我无法测试它,但最简单的方法似乎是将你的条件改为只是匹配你想要重写的名字。
<add input="{HTTP_HOST}" negate="false" pattern="^mysite.com$"/>`?
答案 1 :(得分:1)
尝试更改此行:
<add input="{HTTP_HOST}" negate="false" pattern="^mysite.com$"/>
答案 2 :(得分:1)
如果pattern
是正则表达式,则可以使用
^[^\.]\.[^\.]$
仅重定向没有子域的请求(仅包含一个点)