Skip to content

I want to take my site offline for maintenance natebot

Derek Jones edited this page Jul 5, 2012 · 7 revisions

Category:Approaches::I want to take my site offline for maintenance

Overview:

This approach relies on a) comfort with the command line, and b) use of .htaccess and Apache's mod_rewrite

Approach

If you are using the mod_rewrite method to hide the index.php in your url as detailed in the section "Removing the index.php file" on http://codeigniter.com/user_guide/general/urls.html, you can use the same .htaccess file to specify a file used for site offline maintenance.

I use a slightly different .htaccess file but to the same effect.

RewriteEngine On

# In my case all CI files are outside this web root, so we can
# allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# hide index.php
RewriteRule .* index.php/$0 [L]

# Uncomment line below to send site to offline status
#RewriteRule .* offline.php [L]

To take your site offline, simply SSH into your web node and un-comment the last line in the above .htaccess file.

Note that in the above .htaccess file, any calls to existing files and directories will continue to be served. That means offline.php can use any images, css, or js available in your web root. However if you are wishing to limit access to these files or, say, some other stored files, you need to take a slightly different approach.

You can either write a more sophisticated .htaccess file or simply place the RewriteRule for offline.php to be the very first rule under the RewriteEngine On command.

Clone this wiki locally