php中header自定义404状态错误页面

前端之家收集整理的这篇文章主要介绍了php中header自定义404状态错误页面前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

404页面就是一个告诉搜索引擎这个页面不存在了,同时也提示用户可以选择其它的操作了,下面我来给没有apache操作权限朋友介绍PHP自定义404页面的操作方法.

实例代码如下:

  1. @header("http/1.1 404 not found");  
  2. @header("status: 404 not found");  
  3. echo 'echo 404';  
  4. exit(); 

加载一个404错误页面

实例代码如下:

  1. @header("http/1.1 404 not found");  
  2. @header("status: 404 not found");  
  3. include("../../404.htm");  
  4. exit(); 

也可以在站点中加入.htaccess,实例代码如下:

  1. errordocument 404 /404.html 

如果有apahce配置权限,我们可以修改 httpd.conf,找到:

实例代码如下:

  1. #ErrorDocument 500 "The server made a boo boo." 
  2. #ErrorDocument 404 /missing.html 
  3. #ErrorDocument 404 "/cgi-bin/missing_handler.pl" 
  4. #ErrorDocument 402 xxxxxxx 

修改

实例代码如下:

  1. ErrorDocument 404 /404.htm 

猜你在找的PHP相关文章