My PHP site in maintenance. How you can redirect site visitors to some "site in maintenance" single page?

I heard something about app_offline.htm for ASP.Internet.

Can there be such like for PHP?

  • I would like that each page from "mysite.com" be rerouted to "maintenance.php"
  • I'd rather not perform the minimum modification within the existing site pages, ideally nobody.

Apache version 2.2.15 under Linux
PHP version 5.2.13

You actually don't give enough particulars (server, framework, etc). If you're on Apache, supplment your .htaccess:

# prevent infinite redirect loops
RewriteCond %{REQUEST_URI} !^/back-soon-updating.php$
# not on development server
RewriteCond %{HTTP_HOST} .com$
# let admins enter to verify the update has worked
RewriteCond %{QUERY_STRING} !c=u
RewriteRule .* back-soon-updating.php [L,R=307]

As my Apache within Linux I actually do the next:

Produced ".htaccess" file underneath the site root using the folowing content:

Options +FollowSymlinks
RewriteEngine on

RewriteCond %{REQUEST_URI} !/images/mainetnance.png$
RewriteCond %{REQUEST_URI} !/maintenance.php$

# here filter the developer's IP/
#RewriteCond %{REMOTE_HOST} !^888\.888\.888\.888

RewriteRule $ /maintenance.php [R=302,L]

Would be to remark which i put into filter the .png files, cause I personally use a picture (/images/mainetnance.png) for that maintenance.php, which image should remain visible, due to global redirect.

The PHP way : Create an maintainance.php and add this inside your index.php:

$offline = true; // <== change this to false when you go online again.

if($offline){
  header("Location: maintainance.php");  // <== redirects all to maintainance.php
  exit;
}

There's no "Global way", either you need to configure your webserver, to visit a particular site, or maybe you incorporate a page everywhere, add

header("Location: offline.php");
die();

To redirect your customers temporary.

You need to set proper header in reaction too (HTTP Response Code 503). You will find Apache only methods for doing the work using mod_rewrite and mod_headers

But also for an easy solution with no need of mod_headers, stick to the steps below

  • Make use of your apache conf / .htaccess as pointed out by Coronatus to redirect all customers except designers to some PHP maintenance script. Make certain the redirect is definitely temporary (utilizing a 307 redirect code as pointed out by Zach)
  • Inside your PHP script, set the response header to following at very begining from the script.

header('HTTP/1.1 503 Service Temporarily Unavailable') //send the proper response code

header('Retry-After: 3600') //Retry after an hour

This will enable you to get what you would like.