web做301跳转的方法:
1.例如在web.config文件中的301格式:
<?xmlversion="1.0"encoding="UTF⑻"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rulename="Redirect(命名)"stopProcessing="true">
<matchurl="^(要重定向的页面)"/>
<conditionslogicalGrouping="MatchAll"trackAllCaptures="false"/>
<actiontype="Redirect"url="(重定向到的页面)"/>
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
2.多个页面跳转,代码以下:
<?xmlversion="1.0"encoding="UTF⑻"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rulename="Redirect"stopProcessing="true">
<matchurl="^abc/001.html"/>
<conditionslogicalGrouping="MatchAll"trackAllCaptures="false"/>
<actiontype="Redirect"url="http://"/>
<rulename="Redirect2"stopProcessing="true">
<matchurl="^abc/002.html"/>
<conditionslogicalGrouping="MatchAll"trackAllCaptures="false"/>
<actiontype="Redirect"url="http://"/>
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
//注意:多个页面跳转时,rulename不能相同
3.整站301跳转,代码以下
<?xmlversion="1.0"encoding="UTF⑻"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rulename="WWWRedirect"stopProcessing="true">
<matchurl=".*"/>
<conditions>
<addinput="{HTTP_HOST}"pattern="^需要转的域名$"/>
</conditions>
<actiontype="Redirect"url="http://要转到的域名/{R:0}"
redirectType="Permanent"/>
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
本文来源:https://www.yuntue.com/post/79391.html | 云服务器网,转载请注明出处!