8

It seems easy to create a custom error page in WordPress for a bad page, i.e., a 404 not found - just create 404.php in the theme directory.

I'd like to do the same for a server error, say if a CGI script on my WordPress site does something stupid like divide by 0.

I tried creating a 500.php page in my theme directory but it appears to be ignored. Instead, the 404.php page in the theme directory is called.

It seems that WordPress somehow catches the server error and translates it into a "not found" error and then uses 404.php

How can I make WordPress go to a different custom page in case of a server error (500), as opposed to a simple page not found (404) error?

And before you tell me to put something like ErrorDocument 500 /path-to-custom-error-page in a .htaccess file, already tried that - it gets ignored by the web server, probably because the RewriteRule directives in the same file are used by WordPress to intercept and handle all requests (and no it doesn't matter if the ErrorDocument directive is above or below the WordPress RewriteRule section).

(Note: I tried researching this on my own, but search results are polluted by people complaining about getting server errors with WordPress, not asking how to create a custom page to handle them.)

3 Answers 3

6

Since WP 3.0 you can override the standard error pages that wp_die() uses, with the wp_die_handler filter.

'wp_die' and 'wp_die_handler' are located in wp-includes/functions.php.

Sign up to request clarification or add additional context in comments.

1 Comment

Here's a Gist for anyone who needs something as a 'guide'. :)
5

WordPress will never be able to show your custom error page for a server error (500). You need to create a .html or PHP page, outside of WordPress. Your host may already have something to help you there, many have a folder into which you can put custom error pages, outside the website's root folder.

1 Comment

How to do this on localhost??
0

ErrorDocument 500 … should work in any case if the path is correct. Turn off WordPress's rewrite rules, produce a 500 error, and Apache should either show /path-to-custom-error-page or say it can't find it.

2 Comments

It seems to me that this addresses only static 500 pages. Personally I prefer declaring both static (if there's a problem between apache and the techology you are using) and dynamic ones (if the communication between apache and the underlying technology is fine, and while processing that request you encounter an error and want to show information related to that request's context).
How to turn off Wordpress rewrite rules? disable permalinks altogether?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.