PrestaShop Documentation, PrestaShop Tutorials

PrestaShop enable maintenance mode from code

Enabling maintenance mode in PrestaShop programmatically can be useful when you want to perform updates or maintenance tasks on your online store. To enable maintenance mode in PrestaShop using code, you can create a simple PHP script or modify specific files within your PrestaShop installation. Here are two methods to achieve this:

Method 1: Using a PHP Script

Create a PHP script in your PrestaShop root directory (where your index.php file is located) with the following code:




if (!defined(‘_PS_VERSION_’)) { exit; }

// Define the path to your PrestaShop config file
define(‘_PS_ROOT_DIR_’, __DIR__);

// Include the PrestaShop configuration

// Enable maintenance mode
Configuration::updateValue(‘PS_SHOP_ENABLE’, 0);

// Display a message to inform visitors

// This script should not be accessible directly in the browser, so exit here



This script includes the PrestaShop configuration, updates the ‘PS_SHOP_ENABLE’ configuration value to 0 (maintenance mode enabled), and then displays the maintenance page using Tools::displayMaintenancePage().

To disable maintenance mode and make your store accessible again, set the ‘PS_SHOP_ENABLE’ configuration value back to 1 (enabled).

Method 2: Modifying .htaccess File

Another way to enable maintenance mode is by modifying your .htaccess file. This method is more of a workaround but can be effective. Here’s how to do it:

  1. Open your PrestaShop installation directory.
  2. Locate the .htaccess file and make a backup copy.
  3. Edit the .htaccess file with a text editor and add the following lines to the beginning of the file:
  1. # Enable maintenance mode
    RewriteEngine on
    RewriteCond %{REMOTE_ADDR} !^Your_IP_Address
    RewriteCond %{REQUEST_URI} !/maintenance.html$ [NC]
    RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif|css|js) [NC]
    RewriteRule ^(.*)$ /maintenance.html [R=302,L]

    Replace Your_IP_Address with your IP address. This code redirects all visitors to a ‘maintenance.html’ page except for the IP address specified. You should create a ‘maintenance.html’ file with a maintenance message in your PrestaShop root directory.

  2. Save the changes to the .htaccess file.
  3. When you’re done with maintenance, remove the lines you added to the .htaccess file to disable maintenance mode.

Choose the method that best suits your needs, and make sure to have a backup of your PrestaShop files and database before making any changes. It’s also a good practice to notify your customers in advance when enabling maintenance mode to avoid any inconvenience.



About zohaibk

We develop useful addons for #E-Commerce and #CRM software to provide extra features.#PrestaShop,#Magento,#SugarCRM,#Vtiger & #Android #apps
View all posts by zohaibk →