Skip to content
自定义HTTP错误页
HTML
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
401.html add <title> and <meta viewport> Jun 4, 2019
403.html add <title> and <meta viewport> Jun 4, 2019
404.gif Add files via upload Jun 4, 2019
404.html add <title> and <meta viewport> Jun 4, 2019
500.html add <title> and <meta viewport> Jun 4, 2019
502.html add <title> and <meta viewport> Jun 4, 2019
LICENSE Create LICENSE Jun 4, 2019
README.md Update README.md Jun 4, 2019

README.md

httpErrorPage

基于Hacker themed error page修改而来的自定义HTTP错误页 支持以下状态码:

  • 401 Unauthorized
  • 403 Forbidden
  • 404 Not Found
  • 500 Internal Server Error
  • 502 Bad Gateway

其他状态码请自行填充模板

Installation

apache

ErrorDocument 401 /401.html;
ErrorDocument 403 /403.html;
ErrorDocument 404 /404.html;
ErrorDocument 500 /500.html;
ErrorDocument 502 /502.html;

nginx

error_page 401 /401.html;
error_page 403 /403.html;
error_page 404 /404.html;
error_page 500 /500.html;
error_page 502 /502.html;
location = /error/404.html {
    internal; # 直接访问/error/404.html时仍可返回404状态码,用于搭配Wordpress 404页重定向,详见http://nginx.org/en/docs/http/ngx_http_core_module.html#internal
}

Wordpress

如果你使用Wordpress且url位于域名根目录,所有请求都会转发给WP的index.php处理从而由WP主题而非webserver返回404页

请修改wp-content\themes\当前使用主题\404.php内容为以302重定向至404页

<?php
wp_redirect('https://example.com/404.html');

不想保留软404请查看上方nginx状态码注释

Acknowledgment

You can’t perform that action at this time.