Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to upgrade my site online, I want to show visitors maintenance page till I finish upgrade.

I tried this code

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_URI} !/maintenance.html$
RewriteCond %{REMOTE_HOST} !^888\.888\.888\.888

RewriteRule $ /maintenance.html [R=302,L]

But this code is redirecting all page to maintenance.html, for example going to maintenance.html going to maintenance.html

I want only root directory redirection not sub directories, like to maintenance.html to

Anyone can give me some suggestion.

share|improve this question
Fix your RewriteRule -- '$' matches on every URL. Use '/$' or '/(?:index\.php|index\.html)?$' – kupson Feb 18 '12 at 16:17

Probably you forgot to mention what os, what web server and for what error number!. If it's for Ubuntu linux, Why choosing the difficult way when you can easily do with ErrorDocument?.

Try this if possible,

mkdir /var/www/errors
cd /var/www/errors
#Create your own error document pages with some message or directly copy or use your "maintenance" page
touch 503_error.html 404_error.html

vim /etc/apache2/apache2.conf
#Add the following in this file
Alias /errors /var/www/errors
ErrorDocument 404 /errors/404_error.html
ErrorDocument 503 /errors/503_error.html

Save & Quit
/etc/init.d/apache2 restart
share|improve this answer

Adding this line before your RewriteRule should ignore visitors who are going directly to existing directories on the server:

RewriteCond %{REQUEST_FILENAME} !-d
share|improve this answer

The easiest way to manage this is to change your RewriteRule to only match the URI you want to redirect. In this case, by anchoring at both ends:

RewriteRule ^$ /maintenance.html [R=302,L]

The rule above negates the need for the %{REQUEST_URI} RewriteCond above it. If this is to be placed in your main config rather than a .htaccess file, it should be:

RewriteRule ^/$ /maintenance.html [R=302,L]

Since you look to be doing this in a .htaccess file, the pattern being matched by the RewriteRule directive does not contain a leading slash. This means that when you do this:

RewriteRule $ /maintenance.html [R=302,L]

The Location: header will be sent to the user as


Note the double slash after the domain. This doesn't matter much and is essentially aesthetic in this case, but it certainly can cause problems. Best to do this:

RewriteRule ^$ maintenance.html [R=302,L]

Or this:

RewriteRule ^$ [R=302,L]
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.