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