Sunday, January 23, 2011

Redirect visitors to a "site in maintenance" page?

My site is in maintenance(construction). How to redirect visitors to a "site in maintenance" single page?

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

Is there something similar for PHP?

  • I want that every page from "mysite.com" be redirected to "mysite.com/maintenance.php";
  • I don't want to do the minimum modification in the existing site pages, ideally no one.

Apache version 2.2.15
PHP version 5.2.13

  • In apache with mod_rewrite you can do it easily, just make the first rule something like

    RewriteRule /.* /maintenance.html [L]
    

    If you want to be able to test the site while everybody else sees the maintenance page, you can also add a condition, excluding some IP addresses, e.g.

    RewriteCond %{REMOTE_HOST} ! example.com
    RewriteRule /.* /maintenance.html [L]
    
  • In Apache with mod_rewrite created a .htaccess file in the root folder containing:

    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]
    
    From serhio

0 comments:

Post a Comment