服务器升级,换成了Windows server 2008,IIS6也升级成了了IIS7.5,导致之前直接在IIS6里设置的301重定向无效了,研究了一下web.config发现实现起来挺简单,记下来分享下。
主要实现:把不带www的主域名转向带www的二级域名,避免多入口,下面代码实现把xizhou.com重定向到www.xizhou.com,需要使用改成你的域名即可。
如果你没有设置过web.config,直接复制下面的代码,保存成web.config文件,放到网站根目录下即可,如果已经有该文件,复制标红的rule规则添加到原规则里即可。
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="domain_www" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^xizhou\.com$" />
</conditions>
<action type="Redirect" url="http://www.xizhou.com/{R:1}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
<httpRedirect enabled="false" destination="" exactDestination="true" />
</system.webServer>
</configuration>
|
|