Friday, November 2nd, 2007

Image Hotlinking Prevention with .htaccess

I'm designing some banners and buttons for Ubuntu advocacy. I have no problem with giving the images away [indeed this is why I made them,] however I really can't afford to host them. So before I post them to this site I wanted to ensure that I had some hotlink protection in place.

To accomplish this I've created a new directory under my site's default "images" directory and protected it from hotlinking with an Apache .htaccess file. For future reference here are the contents of the .htaccess file:

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(.+.)?example.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule .*.(jpe?g|gif|bmp|png)$ ../hotlink.gif [L]

The first line of the above code turns on the mod_rewrite engine in Apache. A requirement for the rewrite commands.

The second line matches any requests from the URL example.com [change this to suit your requirements]. The [NC] code means "No Case", meaning match the URL regardless of case.

The third line allows empty referrals.

Finally, the last line matches any files ending with the extension jpeg, jpg, gif, bmp, or png. This is then replaced by the hotlink.gif file [see below] residing in the above images directory.

An example no hotlinking image with message.

If you need to allow more domains to hotlink to your images you can simply duplicate line two. See the example below:

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(.+.)?example.com/ [NC]
RewriteCond %{HTTP_REFERER} !^http://(.+.)?another-example.net/ [NC]
RewriteCond %{HTTP_REFERER} !^http://(.+.)?one-more-example.org/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule .*.(jpe?g|gif|bmp|png)$ ../hotlink.gif [L]

Monday, October 29th, 2007

PHP 5 & Feed Updates

It's been a long time coming but my website [CrunchBang.org] is now finally running on PHP 5. My hosting provider performed the upgrade earlier this month and made the switch optional on a domain basis. Any domain on their servers can run either PHP version 4 [default] or upgrade to version 5 by adding a script handler in .htaccess:

Action php5-script /interpreters/php5-script
AddHandler php5-script .php

My development systems all run PHP 5 so the switch was a breeze. Hopefully from now on I'll be able to avoid stuff like this.

Also, I've been working on my Whird project over the weekend. I've now added feeds for individual tags and updated various features to improve usability. I've had to place some URL rewrites for the new feeds and I'm hoping that the various planets [Planet Ubuntu Users, Planet Ubuntu UK] don't get flooded — I apologise if they do :)


Friday, October 5th, 2007

United Hosting Server Upgrades

My hosting provider is currently performing upgrades to all of their servers. I've been with United Hosting for about 4 years now and I can honestly say that they are the best hosting provider that I've had the pleasure to use.

In the time that I've been with them they have grown enormously and have an obvious commitment to constantly improving their services. I can confidently expect no downtime during this upgrade. It's a nice feeling when you have complete confidence in your host.

Note: I wouldn't normally plug commercial services on my blog. However, respect where respect is due!


Browse Posts by Tag

13th advocacy antispam artwork bash bbc bcs bittorrent bloggers blogs boobs bookmarklets cli code colour commands comments conduit crontab crunchbanglinux debian design development email fluxbuntu fonts fun gedit gimp gnome google gos hack hacks hardware hosting images javascript language launchpad licenses life lincslug linux lugradio madness meme memes microsoft mint misc monkeys motu muppets mysql n95 networking nokia openbox openoffice opensuse packaging penguins php phpmyadmin podcast ppa printer progbox programming projects puppy python random rants realplayer revu scripts security shell software ssh terminal terminator themes tools twitter typography ubuntu ubuntucse unitedhosting video virtualisation webcam webdesign whird wiki windows woot xfce4 zombies