{"id":3873,"date":"2009-09-05T12:04:49","date_gmt":"2009-09-05T19:04:49","guid":{"rendered":"http:\/\/css-tricks.com\/?page_id=3873"},"modified":"2013-01-28T09:39:04","modified_gmt":"2013-01-28T16:39:04","slug":"custom-error-pages","status":"publish","type":"page","link":"https:\/\/css-tricks.com\/snippets\/htaccess\/custom-error-pages\/","title":{"rendered":"Custom Error Pages"},"content":{"rendered":"
ErrorDocument 400 \/400.html\r\nErrorDocument 401 \/401.html\r\nErrorDocument 403 \/403.html\r\nErrorDocument 404 \/404.html\r\nErrorDocument 405 \/405.html\r\nErrorDocument 408 \/408.html\r\nErrorDocument 414 \/414.html\r\nErrorDocument 500 \/500.html\r\nErrorDocument 502 \/502.html\r\nErrorDocument 504 \/504.html<\/code><\/pre>\n

And a PHP template for dealing with any sort of error, if you want to keep it simple:<\/p>\n

<?php\r\n\r\n$status=$_SERVER['REDIRECT_STATUS'];\r\n$codes=array(\r\n      400 => array('400 Bad Request', 'The request cannot be fulfilled due to bad syntax.'),\r\n      401 => array('401 Login Error', 'It appears that the password and\/or user-name you entered was incorrect.'),\r\n      403 => array('403 Forbidden', 'Sorry, employees and staff only.'),\r\n      404 => array('404 Missing', 'We\\'re sorry, but the page you\\'re looking for is missing, hiding, or maybe it moved somewhere else and forgot to tell you.'),\r\n      405 => array('405 Method Not Allowed', 'The method specified in the Request-Line is not allowed for the specified resource.'),\r\n      408 => array('408 Request Timeout', 'Your browser failed to send a request in the time allowed by the server.'),\r\n      414 => array('414 URL To Long', 'The URL you entered is longer than the maximum length.'),\r\n      500 => array('500 Internal Server Error', 'The request was unsuccessful due to an unexpected condition encountered by the server.'),\r\n      502 => array('502 Bad Gateway', 'The server received an invalid response from the upstream server while trying to fulfill the request.'),\r\n      504 => array('504 Gateway Timeout', 'The upstream server failed to send a request in the time allowed by the server.'),\r\n);\r\n\r\n$errortitle=$codes[$status][0];\r\n$message=$codes[$status][1];\r\n\r\nif($errortitle==false){\r\n       $errortitle=\"Unknown Error\";\r\n       $message=\"An unknown error has occurred.\";\r\n}\r\n\r\n?>\r\n<!doctype html>\r\n<html>\r\n<head>\r\n<title><?php echo(\"$errortitle\");?><\/title>\r\n<meta charset=\"utf-8\">\r\n<\/head>\r\n<body>\r\n\r\n<!-- Insert headers here. -->\r\n\r\n<?php\r\necho('<h1>'.$errortitle.'<\/h1>');\r\necho('<p>'.$message.'<\/p>');\r\n?>\r\n\r\n<!-- Insert footers here. -->\r\n\r\n<\/body>\r\n<\/html><\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"

ErrorDocument 400 \/400.html ErrorDocument 401 \/401.html ErrorDocument 403 \/403.html ErrorDocument 404 \/404.html ErrorDocument 405 \/405.html ErrorDocument 408 \/408.html ErrorDocument 414 \/414.html ErrorDocument 500 \/500.html ErrorDocument 502 \/502.html ErrorDocument 504 \/504.html And a PHP template for dealing with any sort of error, if you want to keep it simple: <?php $status=$_SERVER[‘REDIRECT_STATUS’]; $codes=array( 400 => array(‘400 Bad […]<\/p>\n","protected":false},"author":3,"featured_media":0,"parent":3826,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"page-snippet.php","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"sig_custom_text":"","sig_image_type":"featured-image","sig_custom_image":0,"sig_is_disabled":false,"inline_featured_image":false,"c2c_always_allow_admin_comments":false,"footnotes":""},"tags":[],"acf":[],"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages\/3873"}],"collection":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/comments?post=3873"}],"version-history":[{"count":4,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages\/3873\/revisions"}],"predecessor-version":[{"id":20012,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages\/3873\/revisions\/20012"}],"up":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages\/3826"}],"wp:attachment":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/media?parent=3873"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/tags?post=3873"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}