Page Banner

<<"Nifty UNIX tip of the day" [Main Index] "Central Park Snow Fun">>

Bloggers Safety Tip with Apache's mod_rewrite

04 December 2003

Some bloggers have discovered, to their cost, that you have to be very careful about what you blog. People often assume that the Internet is anonymous and what they write in their blogs will not touch their 'real' life. They often forget that their parents, girl/boyfriends or boss may be reading. Even seemingly innocuous things can get you fired as Mike found to his detriment. Below is a simple tip that doesn't stop you from having to think before you blog, but it can help keep your blog away from groups that you may not want to see it. It uses Apache's mod_rewrite that allows you to remap requests for a URL to different files.

This site is a good introduction to setting up mod_rewrite and some of its greater powers. Assuming that you have apache set up with mod_rewrite, you need a new stanza in the httpd.conf file to activate it and specify the rewrite rules.

The goal is to target a range of IP addresses and re-direct all requests to this range to a given page.

The first line turns on the mod_rewite engine (it has to be installed already)

The rule below blocks access to all addresses in the class C range 192.168.0.0 to 192.168.0.255. Notice the '.'s have to be escaped with a '\'

The rule affects requests for all URLS. This is written as '^.*$' which is made up of:
^ - matches the beginning of the URL
. - matches any character
* - matches 0 or more occurances of the previous pattern (any character)
$ - matches the end of the URL

The RewriteCond line specifies the condition for performing the URL rewriting and the RewriteRule specifies the change to be made. You can use RewriteRule without RewriteCond if you want the change to be applied to all matching URL requests.


RewriteEngine on
RewriteCond %{REMOTE_ADDR} 192\.168\.0\.
RewriteRule ^.*$ /missing.html


Apache.org has a detailed reference guide and a A HREF="http://httpd.apache.org/docs/misc/rewriteguide.html">page of good examples showing the power of mod_rewrite.

Lastly, remember this isn't really a 'security' measure, there are a million ways around it. It's just helps to stop unwanted people from stumbling accross your blog.
nav:
home
archives
photos

my other sites:
- New York Running
- ISOGA Heavy Metal Band!
- Vacations in France!

friends:
- simon's scene
- mark's musings

previously:
- More Like it
- Worst Webhost ever?
- Against Bottled Water
- Recovering Disk Space in Windows
- Sun Ray Deployment at IS195
- Running Route Database - Update
- Pics from Mike's Bike Trip
- Central Park Moonlight Cycle
- Kristin Plater's Next Show...
- Kristin Plater Plays the Alphabet Lounge
- Your Chance to Influence US Energy Policy!
- Practical NY Energy Tips - PCs
- Missing the Point
- Practical NY Energy Tips - Lighting
- Making the Switch to Firefox
- Belize to Gutemala and Back Again
- Diving in Cancun
- Today...
- Peru and Belize!
- PC Fix Up Tips

-- powered by Greymatter -- email --