4
确保在IIS 7中托管的网站上所有页面命中的最佳方式是使用www重定向。子域名...下面的例子:在IIS 7中重定向网站的最佳方式
http://site.com ==> http://www.site.com
或
http://site.com/somepage.html ==> http://www.site.com/somepage.html
确保在IIS 7中托管的网站上所有页面命中的最佳方式是使用www重定向。子域名...下面的例子:在IIS 7中重定向网站的最佳方式
http://site.com ==> http://www.site.com
或
http://site.com/somepage.html ==> http://www.site.com/somepage.html
此规则会重定向(301永久重定向)的所有请求http://site.com/somepage.html
为http://www.site.com/somepage.html
(将工作,如果域名= site.com
):
<system.webServer>
<rewrite>
<rules>
<rule name="Force www" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^site\.com$" />
</conditions>
<action type="Redirect" url="http://www.site.com/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
这人会做同样的,但会从任何SUBDOMAIN重定向到www(如hello.site.com => www.site.com
):
<system.webServer>
<rewrite>
<rules>
<rule name="Force www" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.site\.com$" negate="true" />
</conditions>
<action type="Redirect" url="http://www.site.com/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
注:
您需要URL重写V2模块是存在(应与1.x版以及工作,但我不能测试它 - 仅V2左右)。
(很明显)您的网站应该接受这些非www子域名。
此规则需要放置在web.config
的网站根文件夹中。