Stop Hotlinking by .htaccess (How to setup Hotlink Protection in .htaccess)

"Hotlinking”Or also known as leeching, piggy-backing, directly linking, offsite image grabs is a method by which a web page takes images other websites. The more large images and multiple visits on the site that took images is even more traffic and consume more banda (Bandwidth) On the source server. Of course, this applies not only to files. You can retrieve files .mp3And files video and even archives. In these last three cases banda consumption would be much higher and would automatically bring extra costs to the host server.

How can we block other sites to take pictures of our source?

To do the following scenario. We image host and we do not want the images to be retrieved on another web page outside the domain In this case we will do the following.

1. Add a file .htaccess in webrootThe site that are hosted images.

2. In. Htaccess add the following lines.

RewriteEngine On
RewriteCond% {HTTP_REFERER}! Http: // (. +.)? / [NC]
RewriteCond% {HTTP_REFERER}! ^ $
RewriteRule. *. (Jpe? G | gif | bmp | png) $ [L]

This means that files with extensions . Jpg,. Jpeg,. Gif,. Bmp si . Png cannot be retrieved with a direct link from the source, and the site that will take the images will display the image oops.gif Host to

Here is a real case. A "IT BlogHe thought of helping ignorant people stealing tutorials from us. With all sources. The new lines added. Htaccess had the following effect on the site that took images:

Do not know - we teach you

How can we block specific sites to take pictures.

May be other situations in which you want to allow taking images from other websites except some.

RewriteEngine On
RewriteCond% {HTTP_REFERER} ^ http: // (. +.)? [NC, OR]
RewriteCond% {HTTP_REFERER} ^ http: // (. +.)? [NC, OR]
RewriteCond% {HTTP_REFERER} ^ http: // (. +.)? [NC]
RewriteRule. *. (Jpe? G | gif | bmp | png) $ [L]

In the above situation all sites can take pictures from (or from the site for which we edit .htaccess) except for the domains and subdomains of, si Images taken from these three areas will be redirected to / oops.gif.

* Specify as to use The module mod_rewrite must be present in the apache webserver.

Founder and editor Stealth Settings, from 2006 to the present. Experience on Linux operating systems (especially CentOS), Mac OS X, Windows XP> Windows 10 and WordPress (CMS).

Leave a Comment