How to put Magento in maintenance mode with IP filters (the easy way)?

How to put Magento in maintenance mode with IP filters

This is probably the most useful quick tip I can think of that I use all the time. Putting Magento in maintenance mode is an essential part of every site launch and it is used in lots of other situations. Although there are many different ways to do this I found that using a few simple lines of code in the root htaccess file is, by far, the easiest solution I could think of. On top of that, this solution enables you to put all the files needed for the maintenance page (html, images, etc.) into one folder. One more advantage of this method is that if you forget to add your IP address to the filter (whitelist) you can do that at any time through FTP so you will not be locked out of your own site ;)

Before we start I recommend you backup your root htaccess file so you can easily reverse all the changes if anything goes wrong.

First you will need to create a folder called “maintenance” in the root of your Magento site. Put the maintenance page (for example static html file) and all the require resources (like images and css) into the folder you just created. Maintenance page can be anything you like as long as all the necessary files are also located in the “maintenance” folder. Be sure to use relative paths when adding resources (images, css, etc.) to your maintenance page. They should be relative to maintenance folder you just created. You can design the maintenance page anyway you like and add all the content and features you need.

Once you are happy with your maintenance page you need to add a few lines of code into the root htacess file. Add the following code below rewrite engine declaration (“RewriteEngine on”). Make sure you have the rewrite engine turned on and working before adding the code.

## 503 Maintenance mode
	RewriteCond %{REQUEST_URI} !^/maintenance/
	RewriteCond %{REMOTE_HOST} !^127\.0\.0\.1$
	RewriteRule .* index.php [R=503,L]
	ErrorDocument 503 /maintenance/maintenance.html

Add you IP address in the format specified in line four. You can add as many IP addresses as you need and they will all be able to access the site while it is in maintenance mode. All other IP addresses will be redirected to the maintenance page. Leave the as is or it won’t work correctly.

Note that we used 503 redirect which prevents search engines from removing your site from their index.

Save and upload your htaccess file and everything should work fine. Please try this on your local machine or development/staging server before moving it to your live site. I am not responsible if you break your site while trying to make this work! On the other hand if you made the backup like I told you at the beginning you should be OK :) If you experience any problems just replace the htaccess file you worked on with your backup and you’ll be fine (no need to delete the maintenance folder).

That’s it. I hope it will work for you. I haven’t had any problems with it so far though.


Care to rate this post?


Srdjan Stojiljkovic

Frontend Developer

Ex. Inchooer

Other posts from this author

Discussion 6 Comments

Add Comment
  1. RS

    I had to make the following changes to make it work for me. I paste it below just in case someone finds it helpful:

    Options +FollowSymLinks
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_URI} !\.(jpe?g|png|gif) [NC]
    RewriteRule .* index.php [R=503,L]
    ErrorDocument 503 /maintenance/maintenance.html

    Thanks for your post!

  2. Stan

    Thanks for the tip, Srdjan!

    Are there any suggestion how to do the same if I’m using Nginx?

  3. Srdjan Stojiljkovic

    Hi Stan,
    I haven’t played with rewrites on Nginx at all but from what I can tell they are not much different from the ones on Apache.

  4. Hi Srdjan,

    we built a nice little module to give store-owners the possibility to display a maintenance page via backend-administration.

    The blog post is written in German language but you just have to download the module – its multilanguage (de/uk/us)

  5. Hi Srdjan
    Thanks for the tip. It worked really well. Not sure why magento doesn’t have this feature available by default.


  6. Hi Srdjan,

    thanks a lot for the quicktip its very usefull and worked fine. Maybe it will be part of the standards in Magento2


Add Your Comment

Please wrap all source codes with [code][/code] tags.