IIS7用web.config做域名的301重定向跳转示例
IIS7用web.config做域名的301重定向跳转示例。
IIS7以上的服务器支持通过web.config来修改配置。所以我们可以用web.config来做301重定向。
正确的代码如下,假如我从huozheweb.com跳转到www.huozheweb.com,那么web.config的代码可以这样写,新建一个文本文档将下面的这段代码复制进去,并重命名为web.config,然后放到网站的根目录就可以了。
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <rewrite> <rules> <rule name="Redirect" stopProcessing="true"> <match url=".*" /> <conditions> <add input="{HTTP_HOST}" pattern="^huozheweb.com$" /> </conditions> <action type="Redirect" url="http://www.huozheweb.com/{R:0}" redirectType="Permanent" /> </rule> </rules> </rewrite> </system.webServer> </configuration>
说明:IIS设置的原始的代码不生效,所以用上面的代码替换到web.config就可以了。
...