How to use HTACCESS to Block Hotlinking.

Why is Hotlinking is Blocked on this Site?

Blocked hotlinks look like this! This site blocks the hotlinking of images and mp3 files. So unless you want a nice little red cross (as shown on the graphic) to appear instead of your image don't hotlink!

For anyone curious as to what hotlinking is: Its merely where a web page refers to a file from an external web site. Its commonly used on images, audio or video files.

Fine if you get permission, otherwise not! The simple reason is that excessive use can bring down the remote site or lead to additional charges to pay for the extra usage (or bandwidth).

Caution before using .htaccess to block Hotlinking!

Use the following at your own risk! Make sure the server running your web site supports .htaccess files before trying this.

How to Block Hotlinks by using .htaccess.

Copy of .htaccess file.

If you use this you should click on the link above and 'save as' to file '.htaccess' in a text file format.

The <Files ...../Files> portion just stops anyone from looking at the .htaccess file by the way.

Edit the file saved on to your hard disk using notepad (or any text editor) to :-

  1. Replace the and text with the web site address you wish to protect.
  2. You can optionally change the to give permission to a selected site.

When you download it onto your server put it in the root directory. Check that you don't have a .htaccess file already in place, if you do you should add the extra lines to it.

The .htaccess file In this case protects only gif, jpg and mp3 files but it can block any extension.

HTTP Error 403 Forbidden.

After putting the .htaccess file in the root directory. All attempts to hotlink will generate a 403 error message in the web site logs. Here is a sample line.

216.111.nn.nnn - - [20/Apr/2005:00:57:05 +0100] "GET /food/cherry.jpg HTTP/1.1" 403 300 " topicID=599.topic" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)"

in this case the 403 is followed is followed by 300, so a 300 byte error message was generated. Watch out for long error messages they may be worse than the original hotlink itself!

Something like this line:-

ErrorDocument 403 /sitemap.htm

in the .htaccess file would cause the sitemap page to be downloaded and use much more bandwidth than the 300 (odd) bytes used for the 403 error message.