Jamit Software Forum
Welcome, Guest. Please login or register.
August 22, 2019, 12:20:47 am

Login with username, password and session length
Search:     Advanced search
May 5th, 2010 - Jamit Software Launches the Market!
3,080 Posts in 791 Topics by 1,554,386 Members
Latest Member: RodneyWhark
* Home Help Search Login Register
+  Jamit Software Forum
|-+  Jamit Job Board Customers
| |-+  User-to-User Support
| | |-+  Site under construction (maintenance) - BEST way of doing it
« previous next »
Pages: [1] Print
Author Topic: Site under construction (maintenance) - BEST way of doing it  (Read 2138 times)
Peter
Administrator
Hero Member
*****
Posts: 248



« on: September 08, 2009, 03:09:45 am »

This seems to be a common question of Job Board customers...

Question:
How do I disable public (and robots) from accessing my site while I am performing some maintenance work?

Answer:
You can do that like this. Create 2 files, one called 503.php and the other .htaccess (or edit your existing .htaccess file). Be careful, some FTP clients consider .htaccess to be 'invisible', so you may need to change your FTP client's settings to unhide invisible files.

Your .htaccess should contain the following:

Code:
###### UNDER MAINTENANCE status 503 ########
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
#allow only this IP address to have access
RewriteCond %{REMOTE_HOST} !^59\.188\.89\.138$
RewriteCond %{REQUEST_URI} !^/503.php [NC]
RewriteRule .* /503.php
</IfModule>
#############

But the above code needs to be edited. It has to have your IP address (the IP of your computer, NOT your server). Make sure to NOT remove the slashes, because this is a "regular expression".

Create a file called 503.php and put the following code inside the 503.php:

Code:
<?php

// come back in 24 hours
$timeComeBack 24*60*60;

// Prevent caching on client side
header("Cache-Control: no-cache, must-revalidate");
header(&#39;Expires: &#39;.gmdate(&#39;D, d M Y H:i:s&#39;, time() - 365*24*60*60).&#39; GMT&#39;); // Any date in the past

// error 503 header
header("HTTP/1.1 503 Service Temporarily Unavailable");
header("Status: 503 Service Temporarily Unavailable");
header("Retry-After: "$timeComeBack);
header("Connection: Close");

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Under Maintenance</title>
</head>
<body>
<p>This site is temporarily unavailable due to maintenance. Please come back in 24 hours.</p>
</body>
</html>


The files .htaccess and 503.php shall be placed in your public_html folder (the uppermost folder).

If you examine the code above closely, you will notice that there is a header 'Status 503'. This is very IMPORTANT for all the search engine robots, because it tells them that although the site is down, nothing is wrong, and they should come back 24 hours later. (You can modify the time window as you like, but this is not critical. 24 hours is just fine.)

After you finish your maintenance work, edit your .htaccess file by commenting out the newly added lines with # in the beginning of each line, like this:

Code:
###### UNDER MAINTENANCE status 503 ########
#<IfModule mod_rewrite.c>
#Options +FollowSymLinks
#RewriteEngine On
#RewriteBase /
##allow only this IP address to have access
#RewriteCond %{REMOTE_HOST} !^59\.188\.89\.138$
#RewriteCond %{REQUEST_URI} !^/503.php [NC]
#RewriteRule .* /503.php
#</IfModule>
#############

There is no need to remove the 503.php file. Keep it there for next time you perform maintenance.
« Last Edit: September 09, 2009, 02:42:47 am by Peter » Logged

SECURE your site BEFORE you wish you had! Use plugins by COLOSSAL MIND!
Pages: [1] Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.133 seconds with 17 queries.