Fork me on GitHub

Summary: Customize error pages to better serve the audience of a particular site

Custom error pages

In some maintenance scenarios it might be handy to be able to show custom error pages.

Flexible maintenance page

If there is a need to temporary divert all traffic to a single static page (to show an error message or an maintenance message) the best way to accomplish it is by adding to your /data/wordpress/nginx/custom.conf a line like:

rewrite ^(.*)$ /maintenance.html break;

The target of the rewrite can actually be any URL and the temporary view shown to visitors can also reside on another server. This is the recommended way to implement a static maintenance page.

If a file named index.html is placed in the /data/wordress/htdocs/ folder, it will take precedence over the existing index.php file that normally loads WordPress. A static file will always work even if PHP is broken for some reason. A static page might also be useful during a DDOS attack as static content can be served at a much higher rate than PHP generated content.

Custom database connection error page

If WordPress is unable to connect to the database, the PHP file /data/wordpress/htdocs/wp-content/db-error.php will be displayed instead. This file may be customized to show any static or dynamic content instead of the default template.

Custom WordPress (PHP) error page

If any WordPress PHP file contains a fatal error and PHP cannot execute, the server will by default emit error 500 and the site will be served from stale cache. If the site is uncacheable due to bad cache/expiry headers or excessive cookie usage, each visitors will see an error page generated by their own browser.

To customize this error 500 page, add to the /data/wordpress/nginx/custom.conf lines like:

fastcgi_intercept_errors on;
error_page 500 /wp-content/wp-error.php;

With this change the wp-error.php will be displayed. This error page PHP file is independent of the WordPress stack and will work despite PHP errors in WordPress code.

WordPress core maintenance module

Also keep in mind the built-in WordPress drop-in maintenance.php and .maintenance files can be used in Seravo’s environment just like anywhere else. For details see wp_maintenance in the WordPress codex.