Better Way To Prevent Image Hotlinking with .htaccess

What is image hotlinking and how to prevent it?

Image hotlinking — It is someone directly taking the URL from your server and embedding it on their website. It’s kind of image stealing, but most importantly losing your bandwidth. Usually, you have to pay for the server bandwidth. When someone hotlinking the image in their website, it will look like the image is serving from their server. In fact, is serving from your server. Every time the image load on another website, it cost us bandwidth.

So we need to prevent it, I would suggest using .htaccess in apache server.

Step 1. Create .htaccess

If you are not using any .htaccess file you have to create one. You can do this easily by opening a notepad and saving the file as .htaccess. Those who have .taccess just open it.

Step 2. Code that blocks hotlinking

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?domain.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?domain2.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ http://i.imgur.com/a0YYDvt.jpg [NC,R,L]

So what does this code does in our website?

RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?domain.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?domain2.com [NC]

This is the list of the sites allowed for the link the images. so by default, all sites are blocked for hotlinking the images except those listed in the code.

RewriteRule \.(jpg|jpeg|png|gif)$ http://i.imgur.com/a0YYDvt.jpg [NC,R,L]

In between the () are images you intended to block from hotlinking. To add more separate them with”|”

Change the http://i.imgur.com/a0YYDvt.jpg to your image. So whenever someone hotlinking this image will show up. Make sure this image is not in your server as your server is hotlink protected.

You can read original article http://www.tutsplanet.com/better-way-prevent-image-hotlinking-htaccess-736/