Testing a Magento site in maintenance mode

Often you’ll have your site in maintenance mode, but obviously before you show your changes to the world you’ll want to check the site over.

The best way to set Magento into Maintenance Mode is to add a maintenance.flag file to the web root, and there’s a snippet of code in Magento’s index.php which handles this:

$maintenanceFile = 'maintenance.flag';

...

if (file_exists($maintenanceFile)) {
    include_once dirname(__FILE__) . '/errors/503.php';
    exit;
}

You’ll want to set this to also take your IP address into consideration, so just make the following amends and you’ll have added conditional maintenance mode:

$maintenanceFile = 'maintenance.flag';

...

if (file_exists($maintenanceFile) && $_SERVER['REMOTE_ADDR'] != "123.123.123.123") {
    if($_SERVER['REMOTE_ADDR'] == "123.123.123.123") {
        //Do nothing, but it's safer to check if it *is* your IP than *isn't*
    }
    else {
        include_once dirname(__FILE__) . '/errors/503.php';
        exit;
   }
}