首先在ACTION中新建一個文件EmptyAction.class.php,其代碼如下:
<?php
class EmptyAction extends Action{
function _empty(){
header("HTTP/1.0 404 Not Found");//使HTTP返回404狀態碼
$this->display("Public:404");
}
}
?>
使用apache服務器的情況下需在apache中的網站配置中加入 ErrorDocument 404 /404.html 即可。
使用iis服務器的情況下需在iis中的IIS/ASP.net下設置404錯誤頁面。
打開apache httpd.conf配置文件或者新建.htaccess配置文件
首先,修改應用程序根目錄的設置,打開 “web.config” 文件編輯,在其中加入如下內容:
<configuration> <system.web> <customErrors mode=”On” defaultRedirect=”error.asp”> <error statusCode=”404″ redirect=”notfound.asp” /> </customErrors> </system.web> </configuration>
注:上文例中“error.asp”為系統默認的404頁面,“notfound.asp”為自定義的404頁面,使用時請修改相應文件名。
然後,在自定義的404頁面“notfound.asp”中加入:
<% Response.Status = “404 Not Found” %>
php的404頁面:
if(//如果沒有任何結果)
{
//以前是僅僅顯示“該帖子已經不存在”的提示,現在是:
require('/404.php');
@header('HTTP/1.1 404 Not Found'');
@header('Status: 404 Not Found');
exit;
}