iis通过web.config设置404的页面

2024-02-15 17:01:35 举报文章

 第一步,设置web.config

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
	<system.webServer>
		<rewrite>
			<rules>
				<rule name="article">
					<match url="^article-([0-9]+)-([0-9]+)-([0-9]+)-([0-9]+).html$" />
					<action type="Rewrite" url="article.php?fid={R:1}&amp;aid={R:2}&amp;rand={R:3}&amp;page={R:4}"/>
				</rule>
			</rules>
		</rewrite>
		<httpErrors errorMode="Custom">
			<remove statusCode="404" />
			<error statusCode="404" path="404.php" responseMode="ExecuteURL"/>
		</httpErrors>
	</system.webServer>
</configuration>

另外在404.php中设置如下,不然访问是200代码

<?php
require_once("index.php");
header("status: 404 not found");
exit();
?>

我上面是包含了一个首页index.php,你也可以用其他的页面。

如果你认为本文可读性较差,内容错误,或者文章排版错乱,请点击举报文章按钮,我们会立即处理!