Fun with Apache's mod_rewrite - no more stealing my images.

Wed Nov 28 21:09:21 EST 2001

From time to time, I find that people have embedded images from my web server in their web pages. This means people are using my bandwidth without my approval. I don't like that. The last time this happened, I crafted a special image to replace the one that had been embedded on the perpetrator's page.

It happened again.

I fixed it.

Now, whenever anybody attempts to embed one of my images in one of their pages, instead they get another image of my choosing. The one I have chosen was selected for maximum trauma (keep this in mind if you're considering viewing the results). This effectively defaces the perpetrator's site by only modifying my own server configuration.

If you are using the Apache web server, you can do the same thing, with mod_rewrite, by copying the following into your config file (you may need to put this in a "VirtualHost" section):
RewriteEngine on
RewriteLog /var/log/apache/rewrite.log
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://www.ChaosReigns.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.phillylinux.org/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://phillylinux.org/.*$ [NC]
RewriteCond %{REQUEST_URI} !^/bad.jpg$ [NC]
RewriteRule .*\.(gif|jpg|png|bmp)$ /bad.jpg [NC,R]


I wanted to allow images on my server to be embedded in pages on a few servers, those were www.ChaosReigns.com, www.phillylinux.org, and phillylinux.org. Note that I had to include the hostname of my webserver, and also note that you need to include all possible forms of each servers' name (with and without the "www.", etc.). The "[NC]"s make the matches case insensitive.

Results:
Warning, may cause lasting trauma. That's just mud on his face, really.

Before - After (mirror)

You will probably need to hit "reload" when viewing one of these, because of caching.
next:Pepper spray is good.2001-12-08
previous:I can't hunt this season.2001-11-25

Comment on this page.
Return to Adventures index
Return to Darxus' home page.