My name is Stefan Ashwell and when I'm not coding personal projects or painting miniatures, I'm a Software Engineer at Holmes Media in Market Harborough.

This blog is a place for me to write about things that require that little bit extra to solve. We all have gaps in our knowledge and every now and then I need to reach out on search engines or blogs to find an answer. Often, these answers come from multiple sources. This blog serves as a personal resource, but if it's helpful for me I'm sure it'll help others too!

Quick and Easy Maintenance Mode

Posted on 28 June 2015

When moving a website between servers it’s usually a good idea to put the website into maintenance mode, which displays a message to any visitors telling them to check back soon, and also ensures we can transfer the most up to date database and files to the new server before making the switch.

Some content management systems come with a maintenance mode built in, or have plugins you can install to do the job. However, if you’re looking for an alternative, or not using a CMS with the functionality built in, this quick .htaccess solution does the job very nicely.

First off, create a new html page called maintenancemode.html in the root of your website. You can design this page however you like and include whatever message is required. Then put the following in your .htaccess file:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/maintenancemode\.html$
RewriteRule ^(.*)$ [R=307,L]

This rewrite rule forwards the user to maintenancemode.html when they try and access any page on your site. It does so using code 307 which means the redirect is to a temporary page and itsn’t a permanent change in URL.