Hotlinking, Bandwidth Theft and mod_rewrite

Have you seen your bandwidth increase without reason !?!?!
I guess you have…
Hotlinking (Bandwidth Theft) makes your bandwidth limit up!

You have taken a few nice photos with your brand new camera and you have uploaded them to your blog (website) so family,friends and visitors could see them.
That is so… nice.
That is what the HotLinkers said too.

Use the mod_rewrite module of Apache.
Let’s say your site’s url is
Fire up your preffered editor, copy these lines below…

RewriteEngine On
# Uncomment the next line if you have placed your images in a folder called photos. As you can see /photos/ is in root directory and the .htaccess file will take care all the subfolders if you have any...
# RewriteBase /photos/
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?*$ [NC]
RewriteRule \.(gif|jpg|swf|flv|png|JPG)$ [R,NC]

and paste them to a file you will call .htaccess (mind the dot please… it’s important!)
Put the .htaccess file to the folder where your photos are…
That’s all!

Keep in mind that even Google will not be able to HotLink your images. If you want to allow this, just insert this line…

RewriteCond %{HTTP_REFERER} !^http://(www\.)?*$ [NC]

Before the RewriteRule.
Now you are done.

“The great thing about mod_rewrite is it gives you all the configurability and flexibility of Sendmail. The downside to mod_rewrite is that it gives you all the configurability and flexibility of Sendmail.”
— Brian Behlendorf

“Despite the tons of examples and docs, mod_rewrite is voodoo. Damned cool voodoo, but still voodoo.”
— Brian Moore