Question

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

192.168.0.52

For single I have written above it's working.

192.168.0.52,192.168.0.53

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?

Was it helpful?

Solution

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

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

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)) {
    header('Location: http://127.0.0.1/m2ee/Error.php');
    die();
}

If anyone has better approach please update this answer.

OTHER TIPS

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: http://127.0.0.1'); //your page
die();
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top