• Sales: 1-800-961-2888
  • Support: 1-800-961-4454

How Do I Prevent Hotlinking on Cloud Sites?


Using the .htaccess file, you can prevent hotlinking--presenting pictures, videos, or other media from one site on another by means for a link--by denying access to specific files based on the domain requesting the file. Hotlinking makes the person who hosts the media pay for the bandwidth to present it, while not getting any of the viewers on her own website. You can deny domains who would hotlink your media by using mod_rewrite, so don't forget to use RewriteBase!

Fully Denying

Below is an example that will only allow .gif, .jpg and .png files to be accessed from www.example.com and example.com:

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example.com/.*$ [NC]
RewriteRule \.(gif|jpg|png)$ - [F]

Using the above example, another website embedding one of your .gif, .jpg or .png images would see a broken image or the alt text specified in the img tag.

Denying With Another Image

If you want to be even more creative, you can even submit a different image to the other website, such as one that reads Stop Hotlinking or Stop Stealing My Bandwidth! Replacing the images with one like that will usually deliver the right message to the offenders and you could even advertise your own site if you make a custom image--though the above example will ultimately save you more bandwidth since it denies the image altogether. Below is an example that will only allow .gif, .jpg and .png files to be accessed from www.example.com and example.com, while serving hotlinking.png to any other websites requesting these files:

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example.com/.*$ [NC]
RewriteCond %{REQUEST_URI} !^/hotlinking.png$ [NC]
RewriteRule \.(gif|jpg|png)$ http://www.example.com/hotlinking.png [R,L]

Using the above example, another website embedding one of your .gif, .jpg or .png images would see hotlinking.png instead.







© 2011-2013 Rackspace US, Inc.

Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License


See license specifics and DISCLAIMER