如何为网站创建自定义的404错误页面


How do I create customized 404 error page for a website?

在创建404错误页面时,可以修改其他页面的页面内容并创建它。但是怎么做呢?

创建404错误页面后,解释如何重定向。

如何修复断开的链接?

自定义错误页面与Apache 2.2+和PHP

。Htaccess或vhost设置:

# in .htaccess you need AllowOverride in the /error directory
ErrorDocument 404 /error/404.php

自定义错误页面与Nginx和PHP

在nginx服务器配置中添加如下部分:(/usr/local/nginx/conf/nginx.conf)

error_page 404 /404.php;
location  /404.php {
  internal;
}

使用lighttpd和PHP自定义错误页面

在lighttpd配置中添加下面的脚本:

server.errorfile-prefix = "/srv/www/htdocs/errors/status-" 

和错误页的语法类似:

/srv/www/htdocs/errors/status-404.php
/srv/www/htdocs/errors/status-500.php
php 404.

header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");
echo 'The Page'. $_SERVER["HTTP_REFERER"]. ' cannot be found!';

关于

    Apache手册
  • <
  • Nginx教程/gh>
  • lighttpd手册
  • PHP Manual: headerPHP Manual: $_SERVER