0

I need to make some changes (deploy a new template) on my website and I want to temporary redirect all visitors to a maintenance page. I don't know how long it will take to apply the template, I assume a couple of hours and I'd like to be able to enter the site so that I can see a live preview.

Any suggestion? I use PHP and Apache.

flag

3 Answers

2

Carlao's answer is a good solution but if you want a more powerful maintenance system, I rather suggest you to use the 503 error code.

From the Status Code Definitions page

503 Service Unavailable

The server is currently unable to handle the request due to a temporary overloading or maintenance of the server. The implication is that this is a temporary condition which will be alleviated after some delay. If known, the length of the delay MAY be indicated in a Retry-After header. If no Retry-After is given, the client SHOULD handle the response as it would for a 500 response.

Assuming you can create new .php pages, create a maintenance.php file with the following content.

<?php

header('HTTP/1.1 503 Service Temporarily Unavailable');
header('Retry-After: 3600');

?>
<!DOCTYPE html>
<html>
<head>
<title>Maintenance</title>
</head>
<body>
<h1>Maintenance</h1>
</body>
</html>

Then paste the following Apache configuration into your .htaccess file.

RewriteEngine On
RewriteCond %{REQUEST_URI} !/maintenance\.php$
RewriteRule .* /maintenance.php

You can even add more RewriteCond to customize the behavior. For example, you can decide to skip the rule for your IP address so that you can easily check a preview while Apache is serving the maintenance page to all other clients.

RewriteEngine On
RewriteCond %{REMOTE_HOST} !^192\.168\.1\.1
RewriteCond %{REQUEST_URI} !/maintenance\.php$
RewriteRule .* /maintenance.php
link|flag
1

Using the Apache configuration, you can apply a temporary redirection to all pages of your site.

With the HTTP status code 302 tell spider and browser that all pages have been moved temporarily to the maintenance page. When the migration be completed you just remove the configuration.

You can add these rules on your .htaccess file:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.domainname\.com
RewriteCond %{REQUEST_URI} !/maintenance-page\.php$
RewriteRule .* /maintenance-page.php [R=302,L]

(the third line prevents the redirect loop)

link|flag
Nice solution, but I would't return a 302. Rather, you should use 503. Also, the HTTP_HOST directive is not necessary unless you use multiple hosts- – weppos Nov 30 at 11:08
0

If you use a CMS like Joomla this is possible, just put in the main administration page "Under maintenance" and the game is done, in another case, I don't know, put a index.php that alerts users of maintenance, for your preview depends by your CMS

link|flag

Your Answer

Get an OpenID
or

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