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

Hotlinking"Or known as the 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 we do not host images and images can be downloaded to another website outside the scope In this case we will do next.

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 can not be retrieved directly from the source link, and the site will take pictures will display the image oops.gif Host to

Here's a real case. A "IT Blog"Thought to help people ignorant 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: // (. RewriteCond% {HTTP_REFERER} ^ http: // (. +.)? [NC] RewriteRule. *. (Jpe? G | gif | bmp | png) $ [IT]

In the situation above all sites can take pictures on (or website for that edition. Htaccess) with the exception of names from, 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.

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

About the author

Stealth LP

Founder and editor Stealth SettingsIn 2006 date.
Experience on Linux operating systems (especially CentOS), Mac OS X, Windows XP> Windows 10 and WordPress (CMS).

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment is processed.