maintenance redirect: automatically redirecting everyone but you away from the drupal site

Last modified: October 6, 2006 - 01:52

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

With the following snippet

creazion_dev - February 24, 2007 - 13:18

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

 
 

Drupal is a registered trademark of Dries Buytaert.