How to: Protect your WordPress blog from hotlinking

Hotlinking is the use of an image from one site into a web page belonging to another site. Many bloggers are hotlinked, and have their bandwidth used on another websites. Here’s a solution to protect your WordPress blog from hotlinking.

The first thing to do is to create a small image saying something like "Please do not hotlink from my server". and upload it on your blog server.

Then, we'll have to edit the .htaccess file, located in your WordPress blog root directory. When modifying .htaccess, always create a backup.

Append this code to your .htaccess:

RewriteEngine On
#Replace ?mysite\.com/ with your blog url
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?mysite\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
#Replace /images/nohotlink.jpg with your "don't hotlink" image url
RewriteRule .*\.(jpe?g|gif|bmp|png)$ /images/nohotlink.jpg [L]

26 Responses

Oct 19 2008 05:52

Sweet! Thanks for the tip! I’m using it on all of my blogs now! :D

Oct 20 2008 18:31

Its not working on your website. can we have a demo somewhere.

Oct 20 2008 18:37

@Roshan: I didn’t put this hack in place on any of my websites because I sometimes share pictures from one site to another, so I don’t have any demo of this online.

Oct 23 2008 13:20

This is brilliant! I hate people who steals your bandwidth so much… i think it’s a blackhat technique

Oct 28 2008 13:06

Thanks for sharing this great hack. It is very useful because saves the bandwith and protects and gives credit to hard work that is done by posting images.

Nov 02 2008 07:27

Any idea how to do this for nginx?

Nov 02 2008 15:16

This is an excellent tip. I wish more people would do this!

A few days ago I was watching my access log and I noticed over half of the entries were hotlinking to a photo of candy corn I have. So, I used a script similar to this in my .htaccess and then went ballastic on an article called

http://www.aleeya.net/side-note/time-to-stop-hotlinking/aleeya/

about why I am fed up with others hotlinking my images. I do not mind if they download my images and reuse them, but I DO mind if they are hotlinked!

Afterwords I posted the solution I used with a similar .htaccess on another one of my sites so I could remember it

http://www.girlgeekette.net/internet-info/htaccess-how-to-stop-hotlinking/

I did notice mine is a bit different than yours. I am not sure what the differences make as far as the end result. I did learn the hard way that when I used an image, I had to place it in a domain outside of the one I was banning hotlinking from. If I put the image in the same domain I was banning hotlinking from (aleeya.net for instance) it put Apache into a tremendous loop. It might be worth mentioning that so people do not use an image from the same domain it is on. The infinite loops will use up tons of resources on the server.

Also, I added multiple domains that I have (one on each line) of mysite.com so I can use the image on my sites, but anything outside of my domains, people cannot hotlink to. Since, in theory it is ok if I hotlink from one of my domains to another of my domains - just not ok if others do.

Nov 29 2008 23:04

This is really handy to know. I’m wondering if there is a way to tell if someone is hot linking your images?

Jan 05 2009 18:00

Its not working on your website. can we have a demo somewhere

Mar 19 2009 11:51

Hi Jean-Paul. You have a great site with a remarkable layout. It was a great inspiration to myself when I created my own blog.

To my question: How can I avoid, that the images on my own site are redirected to the protection image as well? I am using the plug-in “Smallbox”. With your code I cannot open any of my own pictures anymore. For the time beeing I went back to the original .htaccess.

Best regards,
Florian

Apr 15 2009 20:46

Be careful about this tip. If I am not mistaken you could be penalised by Google. Furthermore you could get some issue when Google Images try to fetch your blog’s picture…any input on what I stated wwill be appreciated

Apr 15 2009 23:57

@Web Talk: Never thought about it! Thanks for the comment, I’ll try to learn more about that !

Apr 27 2009 19:42

Be careful about this tip. If I am not mistaken you could be penalised by Google. Furthermore you could get some issue when Google Images try to fetch your blog’s picture…any input on what I stated wwill be appreciated

I’m still waiting for a response , then I can go ahead and implement the trick

Trackbacks:

Leave a Comment

* Name, Email, Comment are Required
Blog And Make Cash