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

Hotlinking” or known as well as the name of leeching, piggy-backing, direct linking, offsite image grabs is a way by which a web page takes on the images of to another web page. The bigger the images and visits more on the site that took over the images, the more traffic is made and more consumed (Bandwidth) on the source server. Of course, this is not only valid for pictures. Files can be taken .mp3, files video And even archives. In these last three situations the consumption of band would be much higher and would automatically bring extra costs for the host server.

How can we block other sites to take over the images from our source?

Let's make the following scenario. we stealthsettings.com The host for the pictures and we do not want the images to be taken on another web page outside the stealthSeting.com. In this case we will do the following.

1. A file is added .htaccess in webrootthe site on which the images are hosted.

2. In .htaccess, the following lines are added.

RewriteEngine On
RewriteCond %{HTTP_REFERER} !http://(.+.)?stealthsettings.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule .*.(jpe?g|gif|bmp|png)$ http://laurentiu.us/oops.gif [L]

This means that files with extensions .jpg, .jpeg, .gif, .bmp and .png cannot be taken with a direct link from the stealthsetots.com source, and the site will take over the images will display the image oops.gif hostata the laurentiu.us.

Here is a real case. A “IT blog” thought of helping unknowing people stealing tutorials from us. With sources with everything. The lines added by us in .htaccess had the following effect on the site that took over the images:

Nu Stii - Te invatam noi

How we can block certain sites to take pictures.

There may be other situations in which we want to allow the images to take over by other sites, except for some.

RewriteEngine On
RewriteCond %{HTTP_REFERER} ^http://(.+.)?facebook.com/ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(.+.)?hi5.com/ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(.+.)?softpedia.com/ [NC]
RewriteRule .*.(jpe?g|gif|bmp|png)$ http://laurentiu.us/oops.gif [L]

In the above situation all the sites can take pictures from stealthsetts.com (or from the site for which we edit .htaccess) except for the domains and sub-domains from facebook.com, hi5.com and softpedia.com. The images taken by these three fields will be redirected to Laurentiu.us/oops.gif.

*We specify that to use the module mod_rewrite It must be present in Apache Webserver.

Founder and editor Stealth Settings, din 2006 pana in prezent. Experienta pe sistemele de operare Linux (in special CentOS), Mac OS X , Windows XP > Windows 10 si WordPress (CMS).

Home Your source of IT tutorials, useful tips and news. Stop Hotlinking by .htaccess (How to setup Hotlink Protection in .htaccess)
Leave a Comment