Stop hotlinking

by on 29.Nov, 2010 under Linux

I was looking at my webserver logs tonight and saw that there where quite a few sites hotlinking some of our icons and buttons. Putting pictures on the web they are gone in a second but please people, use your OWN bandwidth, not mine. Anyway this made me decide I had to do some .htaccess magic and stop this bandwidth theft. And as always, I thought I’d document it here so someone else can use this if someone is linking in to use their pictures.

The new picture

First I created a new picture to be sent to the hotlinkers. And if they didn’t use image size properties I made it double the size of the old one so hopefully it might mess with their layout a little.
The image created looked like this
No HOTLINK

The .htaccess file

After the new nice image was done I just had to do some .htaccess magic to replace what was sent out to the requesters.

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

That’s it. Now anyone linking in on images will only see the image from the image dump host. You could use imageshack or any other service for this.

Leave a comment

Using htaccess to create a subdomain on apache

by on 20.Feb, 2008 under Linux

I’ve been thinking of starting a blog to keep my thoughts and ideas together in one place. To do this I wanted to use a simple subdomain to nixadmins.net like blog.nixadmins.net. To do this in a simple way without touching too much of the configuration I did it using the Apache’s .htaccess file.

The htaccess file can be used to many things, in this short short story I’ll only go in to creating a working subdomain. But you can find a lot more in the htaccess tutorial.

If you have a .htaccess file you can modify it, if not just create a new one in any editor.
Put the following lines in it, and of course change the values to suite your need.

<IfModule mod_rewrite.c>
RewriteEngine on
# Rewrite for WordPress blog
RewriteCond %{HTTP_HOST} blog.nixadmins.net
RewriteCond %{REQUEST_URI} !blog/
RewriteRule ^(.*)$ blog/$1 [L]
</IfModule>

After that, create a DNS cname record, of blog.nixadmins.net that points to the same server, for me www.nixadmins.net. And you are done.

Leave a comment