Redirect to Maintenance Page Using htaccess

From Lunarpages Web Hosting Wiki

Jump to: navigation, search

How can I redirect to a maintenance page using the .htaccess file?

There are many things you can do with your .htaccess file. One of the more popular solutions is to use it to help you redirect users to another page if you are undergoing maintenance.

Step 1: Create Your Offline Redirect Page

Create an HTML page, and call it something like "offline.html". Inside of that file, put the message you want to show when somebody tries to visit your site while it is being worked on. It could be as simple as just typing into the file (using a text editor) "Upgrading Site, Be Back Later". Once you have created this file, upload it to your public_html directory.

Step 2: Edit Your .htaccess File

You will want to add the following to your .htaccess file:

Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !/offline.html$
RewriteRule .* /offline.html [R=307,L]

This will redirect anybody who checks out any web page on your web site to the "offline.html" file you created earlier. Now, save the changes you have made to the .htaccess file and test it out.

Clear your browser's history and cache, then browse to your domain name. If all was done correctly, you should see your message your "offline.html" page. If you want to go back to normal, just remove the lines you added to your .htaccess file to make the redirect happen.

Share |
Want to read this in another language?
Personal tools