Stop Hotlinking – Protect your server bandwidth

Are you fed up of scrappers who steal your images from your RSS feeds or website by directly using the url, without your permission? This is something which is widely known as IMAGE HOTLINKING. The worst part of Image Hotlinking is not only they are using your images but also sucking your server bandwidth, and if you are on a limited bandwidth plan then every MB counts. Every time the images will be loaded on their website your server bandwidth will be used. So, following are some methods which you can use to prevent Image Hotlinking.

Use of .htaccess file to prevent Image Hotlinking

Every wordpress user have an .htaccess file and if you don’t have or not using wordpress than you should be creating one. Open up your notepad and save it as .htaccess without giving an extension. Now we have to edit the .htaccess file and create a rule in it. Copy the following code in your .htaccess file.

RewriteEngine On

RewriteCond %{HTTP_REFERER} ^http://(www\.)?blockthisdomain\.com(/.*)*$ [NC,OR]

RewriteCond %{HTTP_REFERER} ^http://(www\.)?blockthisdomain\.net(/.*)*$ [NC,OR]

RewriteCond %{HTTP_REFERER} ^http://(www\.)?blockthisdomain\.com(/.*)*$ [NC]

RewriteRule \.(jpeg|JPEG|jpe|JPE|jpg|JPG|gif|GIF|png|PNG)$ Can'thotlink.jpe [L]

Upload this file in the folder where all your images are located for wordPress users it should be wp-content> uploads. This will block every domain you specify in this rule from Hotlinking.

How this rule works?

At the end you will notice that there is a file name called Can’t Hotlink.jpe( you can name it whatever you wish). In real this file works as an JPG extension( can use other extension), the purpose behind of saving this file as an JPE extesion so it won’t get blocked by your .htaccess rule (Note: if you use a Hotlink protected file in this place, your server might go into an endless loop). This file should be uploaded in the same folder and you can use any image you want, just keep in mind that the name of the image should be matching with the rewrite rule name.

Use WordPress settings to stop Image Hotlinking

If you run a wordpress website you must have noticed that the moment you upload a new image while creating a new post a window will pop up. This window will allow you set a descripton, caption, Link URL etc. Link URL is something we need to focus on, rather than using file URL we should choose Attachment post URL. This will link our image to our post link and if some one tries right click >copy link address all he will get is a URL linking to your website. Though .htaccess rule gives you more control this is the method I personally prefer since I don’t have time to look for sites who are using my images. As an example I had linked this image with the post, try to copy the link address and you will get the link address of this post


Use of Cloudflare security features

This tip is for those who are using Cloudflare or planning to use cloudflare as their CDN provider. Cloudflare provides many useful security features without paying a dime and one of the security feature of clouflare is preventing Image hotlinking. By default it is disabled so you have to enable it from their app section.

How to check that you have prevented Image Hotlinking?

To check that your images are hotlinking proof or not head towards this site Test hotlink Protection. This tool also lets you create a .htaccess file if you don’t want to do the coding stuff. Follow this link to create a .htaccess file hotlink protection.