I've configured Magento 2 website as maintenance mode from .maintenance.flag it's working, at the same time I have configured released IPs from .maintenance.ip file.

For multiple IPs not working while for single IP it's working fine.

How can I configure to release selected multiple IPs?

For this I have written I have created.

1) .maintenance.flag file from var.

2) .maintenance.ip file from var and written code for release single IP

For single I have written above it's working.,

For multiple, I have written above it's not working.

Can you please let me know how can I write to release multiple IP's and also how can I configure to redirect particular page while maintenance Mode?

  • 1
    I love this question.
    – Amit Bera
    Commented Jan 5, 2016 at 7:18

3 Answers 3


For activating maintenance mode with IP addresses execute below command in CLI

php bin/magento maintenance:enable --ip="" --ip=""

the above command will automatically create a .maintenance.flag and .maintenance.ip file under root/var folder.

and .maintenance.ip the file contains the above two IP addresses separated by a comma.

For more Information, you can find from devdocs.

The above information is for maintenance mode.

To redirect a custom page while maintenance mode writes below code in root/index.php.

$maintenanceFile =  __DIR__ . '/var/.maintenance.flag';

if (file_exists($maintenanceFile)) {

If anyone has better approach please update this answer.


The Maintenance Mode check-in lib/internal/Magento/Framework/App/Bootstrap.php. This file calls to lib/internal/Magento/Framework/App/MaintenanceMode.php. If .maintenance.flag file exists in var folder, it returns false.

If you want the redirect to a new page when maintenance enables, you need change lib/internal/Magento/Framework/App/Bootstrap.php file. Add this code below after line 288:

header('Location:'); //your page

If you want to design your maintenance page you need to edit file pub/errors/default/503.phtml and for css pub/errors/default/css/styles.css design accordingly.

And in .htaccess page need to comment ## SetEnv MAGE_MODE developer or production for execute this maintenance page.

and if you are in production mode then this page will excute other then below code error will show.

Unable to proceed: the maintenance mode is enabled. 
#0 /backup/html/magento2/vendor/magento/framework/App/Bootstrap.php(256): Magento\Framework\App\Bootstrap->assertMaintenance()
#1 /backup/html/magento2/index.php(39): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http))
#2 {main}

if you want to come back in your website you need to delete var/.maintenance file or run below command in terminal

//For run your website back online.
php bin/magento maintenance:disable  
//For on maintenance mode.
php bin/magento maintenance:enable 

Also set in .htaccess SetEnv MAGE_MODE developer

follow up my youtube and block



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