0

I have successfully put magento 1.9.x in maintenance mode while still having access to admin area however I need to access one more URL which is custom based module. The following code worked fine to access admin area only.

$url=(!empty($_SERVER['HTTPS'])) ? "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] : "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];

if (file_exists($maintenanceFile) && strpos($url,'/admin') === false) {
    $basePath = dirname($_SERVER['PHP_SELF']);
    include_once dirname(__FILE__) . '/maintenance.php';
    exit;
}

How do I add another custom module in above code which has URI eg. www.domain.com/ModuleName/ and can be access directly while keeping the site in maintenance mode?

Thanks

1
file_exists($maintenanceFile) && strpos($url,'/ModuleName') === false && strpos($url,'/admin') === false

or simple base your logic on your IP and send everyone to maintenance mode:

if($_SERVER['REMOTE_ADDR'] != 'your_ip'){
     include_once dirname(__FILE__) . '/maintenance.php';
     exit;
}

UPDATE:

using preg_match:

if(file_exists($maintenanceFile) && !preg_match('#/(admin|ModuleName)#',$url)){
      ...your code
}
  • This worked fine. Thank you! Just wondering if I could do this with an array? – harry Apr 18 '17 at 17:17
  • you can do this with preg_match: !preg_match('#/(admin|ModuleName)#',$url) – Konstantin Gerasimov Apr 18 '17 at 17:23
  • preg_match throwing up the error:- Parse error: syntax error, unexpected '{' in index.php on line 70 – harry Apr 18 '17 at 17:29
  • it means you have spare '{' on line 70. see my updated answer. just copy/paste in an appropriate place. – Konstantin Gerasimov Apr 18 '17 at 17:33
  • yes, you are right, and I actually missed one closing bracket ) before the closing braces. At last, preg_match is better way to achieve this. Many Thanks! – harry Apr 18 '17 at 17:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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