Customizing the response code and message

Posted on May 11, 2021

When this plugin blocks a request, it behaves differently depending on the setting of the “Response code”. This document explains about the details and also how to customize the error page for human.

Response code and behavior

You can select a HTTP status code which is returned to the requester when blocking occurs.

Response code

This plugin behaves differently according to the code you selected as follows:

Redirect URL

You can specify the URL for response code 2xx and 3xx. Front-end URL on your site would not be blocked to prevent loop of redirection even when you enable “Front-end target settings”. Empty URL is altered to your home.

The default value is pointed to the “black hole server” where if the attackers actually redirect to that URL, they never get the result.

Response message

You can specify the message for response code 4xx and 5xx. The default value is:

Sorry, your request cannot be accepted.

Empty message is altered to what given by get_status_header_desc().

Human friendly error page

A human friendly error page is available instead of a dreary page by wp_die() if you select 4xx for client error and 5xx for server error as a response code.

You can find 404.php in your theme directory. Please copy it and give it a name according to the setting of “Response code”. The following picture is a sample of 403.php in Twenty Twelve with BuddyPress.

403 error page

NOTICE: If you select "mu-plugins" (ip-location-block-mu.php) as “Vaidation timing” at “Validation rule settings“, you have some restrictions on using custom filter hooks and human friendly error page. See also this codex.