WordPress – how to add a custom 500 server error page?

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.

Read More

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.)

Related posts

Leave a Reply

3 comments

  1. 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.

  2. 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.

  3. 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.