mod_rewrite for geeks

many people ask us what v00d00 magic we use to serve up a special image that is displayed instead of the snazzy images on our gallery. this is done to prevent bandwidth theft since remote web pages don't actually serve the content. despite what you may think, having these links eventually adds up and kills our bandwidth. once you learn more about mod_rewrite, there is a whole lot of flexibility that i won't even begin to go into. if you do a simple search on google, you'll find much more comprehensive guides. but, for the impatient, here's the skinny:

Step One: If apache wasn't compiled with mod_rewrite, break out the original distribution .tar and recompile. This time, include --enable-module=rewrite as a compile time option.

Step Two: Go to the directory with the content you want to prevent from being directly linked to. Create a .htaccess file that will set up the rule. This WILL affect subdirectories! Plan accordingly.

Step Three: Add the following lines to the newly created .htaccess file. Figure out what image or web page you want the bandwidth mooch to see, and substitute it in under the RewriteRule line. You can also add/remove file types accordingly.

Of course you need to replace attrition.org with YOUR domain, but if you don't suck you would have figured that out. If you actually had to be reminded, this means you should consider making lopsided ceramic ashtrays in a therapeutic art class instead of running a web server.


RewriteEngine on

RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://attrition.org/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.attrition.org/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://forced.attrition.org/.*$ [NC]

RewriteRule \.(png|PNG|gif|jpg|JPG)$ http://attrition.org/visit_attrition-dont_hork_our_bandwidth.GIF [R,L]

Step Four: Notice the absence of 'GIF' and the substitute image named '.GIF'. This is required to avoid a processing loop if you try to rewrite the same image type you link to.

Step Five: Don't ask me questions beyond this, I don't know much more about rewrite.


main page ATTRITION feedback