How do I make my Magento site temporarily unavailable (put into maintenance mode)?

There may be times when you need to perform an upgrade and don't want your website to be accessed during that time. This is important when performing updates that affect the database. When maintenance is being performed, Google search engine rankings could potentially drop, since Googlebot cannot crawl your site.

Using maintenance.flag

The preferred, and easiest approach, is to create a new empty file in your Magento root directory named maintenance.flag. Magento will then automatically display a maintenance page with a 503 header. A 503 HTTP result code will tell Google that your site is temporarily unavailable. For Create Hosting customers on a Magento hosting plan (such as Mage Lite, Mage Plus or Mage VPS), your Magento cron jobs / scheduled tasks are pre-configured to look for the presence of this file and won't execute when the file is present.

Using .htaccess and a 503.php page

Alternatively, you can also create your own 503.php page, along with a .htaccess file and use an optional Retry-After header, which will inform Googlebot when it should attempt to re-visit your site.

Here is an example of restricting access to your website to your computer IP address only. Other visitors (including Googlebot and other search engine spiders) will get the HTTP 503 Service Unavailable error. Make sure you set the date as appropriate though.

1. Create a file 503.php in your Magento installation root:

<?php;
header('HTTP/1.1 503 Service Unavailable');
header('Content-Type: text/plain; charset=UTF-8');
header('Retry-After: Tues, 29 Jun 2011 12:00:00 EST');
echo "503 Service Unavailable";
?>

2. In .htaccess, add the following rewrite rule:

RewriteEngine On
RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.1$
RewriteRule !503.php$ /503.php [L]

Where 127.0.0.1 (note the backslashes before dots) should be replaced with your IP address. You can Google your IP Address using https://www.google.co.nz/search?q=what+is+my+ip

Once you save this .htaccess file, your site will be down until you restore the initial state (just comment out or remove the above 3 lines in your .htaccess file).

Using Nginx and a 503.php page

With Nginx, .htaccess will be ignored. You can however use the following in your Nginx configuration instead:


# redirect to 503 maintenance page
location / {
if ($remote_addr !~ "^127\.0\.0\.1$"){
rewrite !503.php$ /503.php break;
}
}

For Create Hosting Magento customers using Nginx, drop in a support ticket and we'll get that setup for you. 

  • 3 أعضاء وجدوا هذه المقالة مفيدة
هل كانت المقالة مفيدة ؟

مقالات مشابهة

How to upgrade Magento 1.3 to 1.4.1.1

The Magento 1.3 to 1.4.1.1 upgrade is quite complex, as there are many changes to the database...

How to disable compilation in Magento

In general, Create Hosting customers shouldn't need compilation enabled, since our Magento...

How to activate the Mobile HTML5 theme in Magento 1.7 (for Android, Blackberry, iPhone, iPod, Windows Mobile, etc)

Magento 1.7 comes with a new Mobile HTML5 theme out of the box. This should be compatible with...

How to fix broken or slow Sales Order Address editing via Magento Admin

We recently came upon an issue in a Magento 1.5* instance where any attempt to edit the customer...

How to manage end of line / discontinued products in Magento

Store owners often have to deal with the issue of out of stock or discontinued products.  These...