Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

wordpress

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

like image 473
Chirael Avatar asked Aug 29 '12 18:08

Chirael


People also ask

How do I create an error page in WordPress?

In the left-hand menu of the WordPress Admin Dashboard, go to Appearance -> 404 Error Page. Select the page you have just customized as your 404 page and set it as 404-error page that'll be displayedappear by default, when users land on a broken link: Click Save Changes and that's it.

How do I force a 500 internal server error?

Delete your browser's cookies. You can correct some 500 Internal Server Error issues by deleting the cookies associated with the site on which you're getting the error. After removing the cookie(s), restart the browser and try again. Troubleshoot as a 504 Gateway Timeout error instead.

What is 500 Internal server error WordPress?

What Is the WordPress 500 Internal Server Error? The WordPress 500 internal error is an application-side issue and mostly occurs on the server level. Mostly it is caused due to plugin/theme issues, corrupted . htaccess file, database, caching issues, hosting issues, or due to a PHP memory limit.


2 Answers

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.

like image 81
webaware Avatar answered Oct 17 '22 05:10

webaware


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.

like image 27
Natalia Avatar answered Oct 17 '22 04:10

Natalia