What is hotlinking and how can I stop it? (.htaccess)

This article applies to 123-reg Linux Shared Hosting accounts.

This answer will explain what hotlinking is and how you can prevent people doing it to your site.

"Hotlinking"

(also called "hot linking", "leeching", and "bandwidth theft") is when a web page of one website owner is direct linking to the images or other multimedia files on the web host of another website owner (usually without permission, thus stealing bandwidth).

When you have created an image or a multimedia file you usually want to protect it and control the use of it. You may not want people downloading your files and putting them on their own websites with little or no credit to yourself. Hotlinking is when other people use your files directly from your site, meaning that each time the file is viewed through their site, you lose bandwidth. This means that you could end up paying for the bandwidth.

For all 123-reg.co.uk hosting customers there is an easy solution. We have the Rewrite Engine activated, which you can set up to analyse any incoming requests for files and deal with them appropriately.

Using this facility is very easy. You simply need to create an .htaccess file, then add the following code:

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://your_domain_name/.*$ [NC] [OR]
RewriteCond %{HTTP_REFERER} !^http://www.your_domain_name/.*$ [NC] [OR]
RewriteRule .*\.(gif|GIF|jpg|JPG|bmp|BMP|wav|mp3|wmv|avi|mpeg)$ - [F]

This will only allow your sites to display your images and multimedia files

What the code does

  • Line 1 : This Turns the RewriteEngine on.
  • Line 2 : ^ = Begin $ = End of Line
  • Line 3 : Allows request from http://your_domain_name/. [NC] = Not Continue [OR] = or
  • Line 4 : Allows request from http://www.your_domain_name/
  • Line 5 : Applies the rule to specific File Formats [F] = Finish

Tip: To get the | symbol, you will need to press shift + \ , normally located in the bottom left of your keyboard.

You can also allow other sites to share your images, using the code below:

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://your_domain_name/.*$ [NC] [OR]
RewriteCond %{HTTP_REFERER} !^http://www.your_domain_name/.*$ [NC] [OR]
#Trusted Sites - Add Here!!!!
RewriteCond %{HTTP_REFERER} !^http://www.trusted_sites_1/.*$ [NC] [OR]
RewriteCond %{HTTP_REFERER} !^http://trusted_sites_1/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.trusted_sites_2/.*$ [NC] [OR]
RewriteCond %{HTTP_REFERER} !^http://trusted_sites_2/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://trusted_sites_x/.*$ [NC] [OR]
RewriteCond %{HTTP_REFERER} !^http://www.trusted_sites_x/.*$ [NC]
RewriteRule .*\.(gif|GIF|jpg|JPG|bmp|BMP|wav|mp3|wmv|avi|mpeg)$ - [F]

Offer

Answer options

Your feedback was successfully added.

Answer tracking

Track

Watch the content of this article for changes.