Saturday, January 21, 2006

Redirect all but my IP using mod_rewrite

(Command updated Dec 21, 2006 due to issues with Firefox not liking previous method)

Just testing some things on a server I run and wanted to find a way to redirect everyone but myself to a holding page (or another URL). This can be done with mod_rewrite and either set in an .htaccess file or, in my case, your httpd.conf file. Here is the code you'd need:

RewriteCond %{REMOTE_ADDR} !^12\.34\.56\.78$
RewriteRule .* /down.html

Where xxx.xx etc. represents your IP address and newaddress.net is the URL or file you wish anyone not at xxx.xx to be redirected to. As ever I hope this helps anyone else like myself who spent a good half hour or so looking for a solution. Credit goes to final post in this thread.

No comments: