Site icon Web Niraj

Using .htaccess Files to Show Maintenance Page

When it comes to updating a database or your code in a production environment, or even migrating code between old and new servers, you don’t want someone accessing your files during your deployment procedure. Why? In the case of database updates, access to your database during an update could cause data inconsistencies, corruption or worse.

During any server maintenance, I’ve found that using a .htaccess file to display a ‘maintenance’ message extremely useful. Anyone accessing any web page on my server (or sub-directory) would see the maintenance message.

Requriements

How does it work?

Create a file called maintenance.html in your web root directory, e.g. https://www.somedomain.com/maintenance.html. Add your maintenance message in this file.

Then create a .htaccess file when you want the maintenance message to appear. E.g. If you want the entire website inaccessible, create a .htaccess file on your web root: https://www.somedomain.com/.htaccess.

In this file, copy and paste the below code:

RewriteEngine on
RewriteCond %{REQUEST_URI} !/maintenance.html$
RewriteRule $ /maintenance.html [R=302,L]

Exit mobile version