views:

74

answers:

2

Hi,

I'd like to implement mod_rewrite to put my site into maintance. Basically all ips except a handful we specify would be forwarded to a static html page.

Please can someone help with this rule. Also is there a way to turn this on and off easily without editting the htaccess file?

Thanks, Josh

+2  A: 

You can use the REMOTE_ADDR variable in a RewriteCond

RewriteCond %{REMOTE_ADDR} !^10\.0\.1\.1$
RewriteRule ^ /maintenance.html

Just change the condition to match the IPs you want, for more than one you can use ^(ip1|ip2|...|ipn)$.

About how to disable the maintenance mode without changing the .htaccess file I think that's not possible short of writing a program that would delete it or otherwise modify it, an easy one would be to rename it.

Vinko Vrsalovic
Don’t forget to mark the start and end in your regular expression.
Gumbo
A: 

you could enable this state and disable it via some admin interface that is able to write to .htaccess (e.g. permissions set to 755 or 777). it would just always find the .htaccess, insert those two lines at the beginning and on disabling maintenance it would delete those two lines, leaving the rest of the file untouched

dusoft