Web Niraj
  • Facebook
  • Flickr
  • Github
  • Linkedin
  • Twitter
  • YouTube
Online portfolio, code examples and developer blog
  • About
  • Contact
  • Portfolio
  • WordPress
Search the site...
  • Home
  • Blog
  • Using .htaccess Files to Show Maintenance Page

Using .htaccess Files to Show Maintenance Page

0

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

  • Linux Server
  • Apache HTTP server with mod_rewrite module enabled
  • Apache config that allows override (AllowOverride All)

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]

Apache, Deployment, Linux, Tutorial

Leave a ReplyCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

StackExchange / StackOverflow

profile for Niraj Shah on Stack Exchange, a network of free, community-driven Q&A sites

Support Me

Buy Me a Coffee

PSN Profile

Tags

ACL Amazon Amazon Web Services Android Android 4.4 KitKat Android 5.0 Lollipop Apache Backup Bug Command Line Cordova cPanel / WHM Facebook Facebook Graph API Facebook PHP SDK 4.0 Facebook Social Plugins Fan Page Firewall Flash Gadget Geolocation Google Nexus 5 Hacking HTML5 iOS JavaScript jQuery Laravel 5 Linux NodeJS Parse PDF PHP Plugin Portfolio PS4 Review Security Server SSH SSL Sysadmin Tutorial WordPress WordPress Plugins
© 2011-2025 Niraj Shah
  • Blog
  • Portfolio
  • WordPress
  • About Me
  • Contact Me
  • Privacy Policy
Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Privacy Policy