In this post, we will see how we can show users a maintenance page that displays a text like Site is undergoing maintenance, we will be back soon.

  1. To put a website in maintenance mode, you need to create an empty file maintenance.flag in your website’s root folder. Magento will automatically show the maintenance page till the file is present.
  2. Go ahead, create this file and try to browse your website.
  3. Now what if you want to access your website and want to show the whole world the maintenance page? We can do this from the index.php file in the root directory. Find this line in the file:
    if (file_exists($maintenanceFile)) {
           include_once dirname(__FILE__) . '/errors/503.php';
           include_once dirname(__FILE__) . '/errors/503.php';
           exit;
    }
    
    

    Now modify these lines to the following code:

    $allowed_ips = array("192.168.1.5");
    $ip = $_SERVER['REMOTE_ADDR'];
    if (file_exists($maintenanceFile) && !in_array($ip, $allowed_ips) {
        include_once dirname(__FILE__) . '/errors/503.php';
        exit;
    }
    
    

    To get your IP address, go to google and type: what is my ip and it will show your IP address. You can replace 192.168.1.5 with your IP address.

  4. Now, let us change the HTML of the displayed error page. Open the file:
    errors\default\503.phtml
    
    

    Create a good looking page and you are good to go.