How to stop file hotlinking and bandwidth theft

In today’s post we will show you how to stop file hotlinking and bandwidth theft to protect your site’s images and media files from being hotlinked and your bandwidth stolen.


stop-file-hotlinking-and-bandwidth-theft

An example of hotlinking and bandwidth theft

When I visit to your website and I like the image or mp3 file on your website and I want copy that file on my site. Then I will use the full URL of your file on my website, this file is downloading from your website every time someone looks at my web. That is bandwidth theft. When you enable Hot Link Protection, I can not steal your website bandwidth anymore.

Stop file hotlinking and bandwidth theft in Nginx

If you have a website about music, photos so Preventing bandwidth theft is very important. Bellow are simple step by step to help you stop and prevent Hotlink Bandwidth Theft, Hotlinking and File Leeching.

To disable hot link protection, please do the following:

– Add this code inside your Nginx configuration file:

server {
..........
location ~ \.(jpe?g|png|gif)$ {
valid_referers none blocked yourdomain.com *.yourdomain.com;
if ($invalid_referer) {
return 403;
}
}

yourdomain.com and all subdomains of yourdomain.com will not be blocked images when using the files on the VPS. If you want to add more formats, just use this “|” .

– You also can use this code to prevent hotlink and file leeching all folder name with images.

server {
..........
location /images/ {
valid_referers none blocked mysite.com *.mysite.com;
if ($invalid_referer) {
return 403;
}
}

– With .zip and .rar file you can use:

location ~ \.(zip|rar)$ {
valid_referers none blocked mysite.com *.mysite.com;
if ($invalid_referer) {
return 403;
}
}

Above is how to stop file hotlinking and bandwidth theft in Nginx so how about stop Hotlinking and Bandwidth Theft with .htaccess ? You will have answer now.

How to stop Hotlinking and Bandwidth Theft with .htaccess

If your website is www.mysite.com. To stop hotlinking of your images from other sites and display a replacement image called stopHotlinking.gif from an image host, use this code in your .htaccess file:

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?mysite\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule .*\.(jpe?g|gif|bmp|png)$ http://i.imgur.com/stopHotlinking.gif [L]

Stop hotlinking from some outside domains such as website-theft1.com, website-theft2.com and website-theft3.com, but allow any other web site to hotlink images:

RewriteEngine On
RewriteCond %{HTTP_REFERER} ^http://(.+\.)?website-theft1\.com/ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(.+\.)?website-theft2\.com/ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(.+\.)?website-theft3\.com/ [NC]
RewriteRule .*\.(jpe?g|gif|bmp|png)$ http://i.imgur.com/qstopHotlinking.gif [L]

Wish you success.

Leave a Reply

50% off over 500 items. Grow your toolkit for all projects. Design, build, produce.Cyber Monday