Restrict access to your website

Jan 12

It is also highly encouraged to restrict access to your website while repairing the database or making upgrade. Here is an example of restricting your website instance to your IP address exclusively. Other visitors, including search spiders, will get the HTTP 503 Service Unavailable error.

Create a file 503.php in your website root:

<?php
header('HTTP/1.1 503 Service Unavailable');
header('Content-Type: text/plain; charset=UTF-8');
echo "503 Service Unavailable";

In .htaccess or in Apache server configuration, add the following rewrite rule:

RewriteEngine on
RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.1$
RewriteRule !503.php$ /503.php [L]

Where 127.0.0.1 (note the backslashes before dots) should be replaced with your IP-address.

Once you save this .htaccess file or reload Apache configuration, your site will be down until you restore the initial state.

468 ad