Prevent Direct Linking of Images From Your Website

Relatively new webmasters generally link an image that is hosted on an external web server. It can be your web server. This practice is called hotlinking of images.

This is not good for you since you have to pay for the additional bandwidth used by their websites. Additionally, if the site that directly links an image from your server, gets a lot of traffic, it can slow down your own website.

How To Prevent Hotlinking? To stop others from directly linking an image hosted on your web server you need to edit your .htaccess file. You can find this file in the root directory of your website on your web server, that is, the public_html directory. You will also need a FTP software like Filezilla to edit this file.

Login to your web server via FTP and download the .htaccess file on your computer. Now open it in any text editor and add the following code in it:

#Stop Image Hotlinking
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http(s)?://(www.)? [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !google. [NC]
RewriteCond %{HTTP_REFERER} !search?q=cache [NC]
RewriteCond %{HTTP_REFERER} !msn. [NC]
RewriteCond %{HTTP_REFERER} !yahoo. [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)? [NC]
RewriteRule \.(jpe?g|png|gif)$ [NC,R,L]

Don’t forget to replace with your actual domain name. And also upload a placeholder image, which will be shown instead of the hotlinked image on any external web server. I have used angry.gif image in the code but you can use any other image you like.

What does this hotlinking prevention .htaccess code do?

The first two line of this code containing allows all the pages on your website to show images as before.

Second line allows blank referrers as well because some browsers and proxy firewalls sends no references while making a request to a web server.

Third, fourth, fifth and sixth line allow search engines to list our images in their searches.

Fourth line allows your feedburner to get images from your blog and display them in rss feeds.

And the last line is the best one. You can upload any custom picture on your server. After adding this code to your htaccess file, all those who have already hotlinked your images would get that custom image you set in here.

share on twitter

Leave a Reply

© 2009-2013 TechyLabs · All Rights Reserved
A threeroutes media Publication