protect-content

If you own a website that publishes a lot of interesting photos or media, "hotlinking" is pretty annoying. Hotlinking is a term used on the Internet that refers to the practice of displaying an image on a website by linking to the same image on another website, rather than saving a copy of it on the website on which the image will be shown.

It's one thing to just copy images from another website and use them for your own. If they are already royalty free and public domain then it isn't as much of a problem, though if not then you're violating someone else's intellectual or creative property. But not even bothering to download and host the image on your own website is a bit more obnoxious, but it can also cost other people money. Depending on the number of hotlinkers, and the size of the file, the hosting costs and bandwidth can get quite high.

Below is a simple way to put a stop to this practice (at least to your website) by causing any hotlinked image requests to return a different image of your choice. Using an image that is pointing out what is being done can be a way to encourage other's to not exhibit this type behavior.

Simply add the below code to your website's .htaccess file:

 

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

 

- and a different version that accomplishes this:

 

RewriteEngine On 
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?mydomain\.com/ [NC] 
RewriteCond %{HTTP_REFERER} !^$ 
RewriteRule .*\.(jpe?g|gif|bmp|png|jpg)$ /images/stop-hotlinking.gif [L] 

Keep in mind that the .htaccess file is a very important part of your website's internal architecture. Introducing errors into the code inside this file can cause strange behavior with your website or even have it crash. Be sure to test this out locally first, and make a backup copy of your .htaccess before deploying additions like these.

 

Having trouble customizing your Drupal setup?

We might be able to help you! Contact Us