eECHO BLOG

A journey of a thousand miles starts with a single step.

How To Prevent Hotlinking

http://riteturnonly.com/2009/04/05/how-to-prevent-hotlinking/

5 April 2009 under WordPress

Hotlinking otherwise known as bandwidth stealing refers to the practice of directly linking to non-html objects on another server. This may be any number of things but most often involves image files. Why some people engage in this practice is beyond me but I assume many of the times it is simply a matter of not knowing better. Whatever the motivation the cost can add up quickly.

Let’s say for an example you have a 100K JPEG that is hotlinked on a site that gets 1,000 hits a day – that’s 100MB of data transferred from your site. You can see what I mean when I say it can get costly. Fortunately there are a few things you can do to discourage this practice.

The first method is to simply ask the offender to cease and desist. As I said earlier in many cases the hotlinker probably didn’t know better and would be happy to comply. Explain to them how to save the image to their own server. Of course this option may not be ideal in all cases. Perhaps you can’t find any contact info on the offending site. Maybe the hotlinker refused your request. It could be that you have an ongoing problem with numerous individuals and contacting them all is not practical. If so let’s move on to the next step.

Using the .htaccess method:

If you want to block hotlinking add the following to your blog’s .htaccess file …

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?yoursite.com/.*$ [NC]
RewriteRule \.(gif|jpg|png)$ – [F]

This will result in a failed request any time someone attempts to hotlink to a gif, jpg or png file. If you’re feeling a little mischievous and want to serve up an alternate file rather than block the request then use the following …

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?yoursite.com/.*$ [NC]
RewriteRule \.(gif|jpg|png)$ http://www.yoursite.com/alternate.gif [R,L]

What this does is serve up alternate.gif anytime someone attempts to hotlink one of your images. This is where you get to use your imagination.

Using a plugin:

If you’re not comfortable mucking around with your .htaccess file then this method is for you. Download and install the Hotlink Protection Plugin. Activate it then head over to Settings > Hotlinking Protection to configure it. You will see the screen below. (click to enlarge)

configure

All you need to do is enter the directories you wish to protect each on its own line. The plugin comes with a default image but if you’d rather use your own custom image (again, your imagination comes into play here) be sure to check the Use a custom image box and fill in the Information image field. Obviously this plugin won’t prevent hotlinking but does provide an interesting method for dealing with the problem.

For an even more involved approach you may want to peruse an excellent tutorial by A List Apart.

credit: hotlinking image on front page courtesy imagechef.com
TalkPress Coming Together
Leave a Reply
Click here to cancel reply.

Name (required)

Email (required)

Website (optional)

Please read this before commenting. (Opens in new window or tab)
Thank you for your contribution.

More News From This Category

* In Defence of the WordPress Support Forum
* Display List of Scheduled Posts
* CSS Tooltips
* Redirect Users To Front Page After Login
* WordPress 2.7 Visual Concepts
* How To Show Most Popular Posts Without a Plugin
* Plugin Review: Widgets Reset
* Split Categories Into Two Columns
* Add a Tabbed Interface to Your Sidebar
* How To Prevent Hotlinking
* TalkPress
* Trim Post Titles
* Plugin Review: Front-end Editor
* Twitter Meets WordPress
* Keep Your Images In Check
* WordPress Magazine Themes Revisted
* Hide Themes When Using Theme Switcher Plugin
* Make Sure Visitors Use Your Latest Style Sheet
* How To Enable Or Disable Comments Quickly
* WordPress Handbook
* ARCHIVE FOR ‘WordPress’ CATEGORY ยป

Comments are closed.