Community Documentation

Maintenance redirect PHP snippet

Last updated April 21, 2012. Created by Dublin Drupaller on June 27, 2005.
Edited by richardhayward, pwolanin. Log in to edit this page.

PLEASE NOTE! The following snippet is user submitted. Use at your own risk! For users who have setup drupal using an alternate database to the default (MYSQL), please note that the snippets may contain some database queries specific to MYSQL.

<?php
/**
* This php snippet redirects everyone but you away from the drupal site
* to a htm page. Useful for "undergoing maintenance" type occasions
*
* put this snippet at the very top of your INDEX.PHP file in your root drupal folder
* or in your front_page settings page and place your closed.html
* file in the same folder.
*
* change the your_ip address to be your IP address so you can
* still access the site
*
*/

$your_ip = '100.100.0.1';
if (
$_SERVER['REMOTE_ADDR'] != $your_ip && $_SERVER['HTTP_X_FORWARDED_FOR'] != $your_ip) {
 
header('location:closed.html');
}
?>

Thanks to themuso for improving the snippet

Comments

With the following snippet

With the following snippet you can easily redirect the user if your site is under maintenance.

Paste this in your theme template.php file:

function phptemplate_maintenance_page($content, $messages = TRUE, $partial = FALSE){

  return header('Location: closed.html');

}

---------------------------------------------
www.creazion.de

About this page

Drupal version
Drupal 4.5.x or older, Drupal 4.6.x, Drupal 4.7.x

Reference

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.