先来看下,web.config中的301格式
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | < ?xml version="1.0" encoding="UTF-8"?> <configuration> <system .webServer> <rewrite> <rules> <rule name="Redirect(命名)" stopProcessing="true"> <match url="^(要重定向的页面)"></match> <conditions logicalGrouping="MatchAll" trackAllCaptures="false"></conditions> <action type="Redirect" url="(重定向到的页面)"></action> </rule> </rules> </rewrite> </system> </configuration> |
多个页面跳转代码如下,以此类推
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | < ?xml version="1.0" encoding="UTF-8"?> <configuration> <system .webServer> <rewrite> <rules> <rule name="Redirect" stopProcessing="true"> <match url="^abc/001.html"></match> <conditions logicalGrouping="MatchAll" trackAllCaptures="false"></conditions> <action type="Redirect" url="http://"></action> </rule><rule name="Redirect2" stopProcessing="true"> <match url="^abc/002.html"></match> <conditions logicalGrouping="MatchAll" trackAllCaptures="false"></conditions> <action type="Redirect" url="http://"></action> </rule> </rules> </rewrite> </system> </configuration> |
多个页面跳转时,rule name 不能相同
整站301跳转
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | < ?xml version="1.0" encoding="UTF-8"?> <configuration> <system .webServer> <rewrite> <rules> <rule name="WWW Redirect" stopProcessing="true"> <match url=".*"></match> <conditions> <add input="{HTTP_HOST}" pattern="^需要转的域名$"></add> </conditions> <action type="Redirect" url="http://要转到的域名/{R:0}" redirectType="Permanent"></action> </rule> </rules> </rewrite> </system> </configuration> |