October 30, 2011 in Apache & htaccess, Programming, Tutorials by admin

Web developers will no doubt need to limit access to their websites during a maintenance time when files are being updated on the server. You have probably seen these pages on various websites with the page decorated in funny images and quotes letting you know the website is offline. There is a really easy way to redirect your website visitors to a maintenance page with only a few lines of text.

Using our .htaccess file we can redirect all user requests to a specified maintenance page.

Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/maintenance\.html$
RewriteRule ^(.*)$ http://domain.com/maintenance.html [R=307,L]

Just change the domain to your domain and the maintenance page to your html file. Place this code in your .htaccess on the root of your web server and you should be set! Always make sure you backup your old .htaccess file before overwriting it.