Are strange web sites showing up in your referer logs? Are people linking directly to images or movies on your website without your permission? Want to stop them? If so, read on.
People who display your images or movies on their site by linking directly to your site are engaging in “hotlinking” or “bandwidth leeching.”
Is it the end of the world? Probably not. Heck, I’m flattered that anyone might be interested in a photo I have taken. But, this practice can consume your bandwidth and slow down your web server. If it is excessive, you might even end up footing an extra bill from your hosting provider.
One tell-tale sign of hot linking is the appearance of strange web sites in your referer logs. I first became aware that this was happening on my site when I started seeing myspace.com and other similar URLs showing up in my logs. These sites wouldn’t normally be interested in my site, so I knew something was up. Upon visiting some of these pages, I noticed my photos were posted there. And sure enough, they hadn’t made a copy of my photo. There were linking directly to the photo hosted on my web site.
Another sign of hot linking might be a higher than normal amount of bandwidth consumption. Your log analysis tools might even show a higher number of hits for an image than for the page that displays it.
The only 100% fool-proof way to stop hot linking is to turn off your web site. But, that’s a little extreme.
One way to slow down hotlinking is to redirect these requests to another image of your choosing. For example, let’s say crazyaboutcats.com is hot linking to your prized photo of your cat Max. By implementing a redirect on your site, crazyaboutcats will now see an image that says, “Please stop hotlinking to my photos” (or something more devious.)
Some people recommend a white list approach. That is, to block all referers except for those that come from sites that you allow. I think that’s a little extreme.
It is hard enough to get people to come to my site. I don’t want to accidentally block legitimate requests from search engines, feed readers, etc.
So we’re going to take a black list approach and block some specific sites that are the worst offenders.
Ask your web hosting provider if you are not sure about any of this.
Create a friendly image that you would like to show to the hotlinkers and upload it to your web server.
Here is the one I’m currently using.

Create a text file called .htaccess that contains the following:
(without the leading line numbers of course)
- RewriteEngine on # Attempt to stop hot linking from these specific sites RewriteCond %{HTTP_REFERER} ^(.+\.)?xanga.com/ [OR] RewriteCond %{HTTP_REFERER} ^(.+\.)?livejournal.com/ [OR] RewriteCond %{HTTP_REFERER} ^(.+\.)?myspace.com/ RewriteCond %{REQUEST_URI} !/path/to/your/stop.png RewriteRule .*\.(gif|jpg|png|avi)$ http://yoursite.com/path/to/your/stop.png
Let’s look at what each one of these lines does.
Of course, you should replace lines 3-5 with the sites that you want to block and update lines 6 & 7 with the appropriate paths.
This .htaccess file should go in your web site’s root directory on your web server.
Make sure everything is working properly on your site. Mod_rewrite is very powerful, but one typo and all hell can break loose.
Check out a site that you have blacklisted and see if your stop image is now being shown where your cat Max used to be.
What other approaches have you used for fighting hotlinking and bandwidth leeches?
No comments yet.