温馨提示×

如何设置404页面301跳转首页

小新
162
2021-01-06 15:56:04
栏目: 编程语言

如何设置404页面301跳转首页

设置404页面301跳转首页的方法:

在网站根目录下,通过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="^123.com$" />

</conditions>

<action type="Redirect" url="http://www.123.com/{R:0}" redirectType="Permanent" />

</rule>

</rules>

</rewrite>

</system.webServer>

<system.webServer>

<httpErrors errorMode="DetailedLocalOnly">

<remove statusCode="404" />

<error statusCode="404" path="/404.htm" responseMode="ExecuteURL" />

</httpErrors>

</system.webServer>

</configuration>

第一段是设置301重定向,第二段是设置404页面。

0