Only-me Access mod_rewrite Rule Generator

This page will generate the mod_rewrite rules needed to redirect "normal" website users to an "update in progress" page, whilst letting a chosen few see the website being updated.

It's explained in more detail on my blog post How To Redirect Users To an Updating Page When Modifying Your Website.

Copy the following lines into the .htaccess file on your website:

	# First turn on mod_rewrite if you haven't already
	RewriteEngine On

	# If this .htaccess file lives in a sub-directory of your website,
	# uncomment the next line and put the sub-directory in place of "mydir"
	#RewriteBase /mydir

	# If the user isn't coming from 'my' IP address...
	RewriteCond %{REMOTE_ADDR} !^$
	# (if you want to be more restrictive then uncomment the
	# following line to only allow the browser you're using now)
	#RewriteCond %{HTTP_USER_AGENT} !^
	# ...and hasn't requested one of our "update in progress" files...
	RewriteCond %{REQUEST_URI} !.*updateinprogress/.*
	# ...then redirect them from wherever they were trying to go to our
	# "update in progress" page instead.
	RewriteRule ^(.*)$ /updateinprogress/ [R,L]
        

For a detailed explanation of what these rules do, check the mod_rewrite documentation.


McQN.net : Projects

© Copyright 2004-2010 Adrian McEwen