“NO Hotlink” - Protect your website from hotlinking with htaccess

January 6, 2008

If you have a website running on Apache and Linux System, you can disable hotlinks.

Hotlinking is when a website or blog use your image with a direct link, so result a consuption of your website bandwith. I assume that I’ve posted a photo of 2MB on my blog and people use it on their webpage without reuploading my photo on their host. Posted Photo was viewed 200 times in 1 hour and consume 400mb of traffic only in 1 hour!! In a day became 9.6 GB of traffic and for website that hosted this photo not is good. Also, there are other many reasons to block hotlinking but this article would be only a solution to prevent hotlinking.

First of all you have to upload one image called no_hotlink.gif on your images directory of your website. (this image is attached below)

No Hotlink

no_hotlink.gif (to download it: right click and “Save Image As”)

Now you have to create a file called .htaccess and upload it on your root directory of your website, changing the text “smokinglinux.com” with the url of your website.

Copy and Paste this code on your .htaccess:

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(www\.)?smokinglinux\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule \.(jpeg|gif|bmp|png)$ images/no_hotlink.gif [L]

Related Post

One Response to ““NO Hotlink” - Protect your website from hotlinking with htaccess”

  1. Remeber to put the video file types *.avi, *.mpg etc. too.
    If exist, maybe musik files too.

    An alternativ ist to put this in the Apache Config (VirtualHosts):

    order deny,allow
    Options -Indexes
    deny from all
    allow from localhost

Leave a Reply