.htaccess – How To Stop Hotlinking
Written by The Geekette on October 29, 2008 – 8:02 pmPosted in Internet | 13 Comments »
Using an .htaccess file in the root of your site, you can stop others from hotlinking to your files. Whether it is images, .zip files or executables, others hotlinking to them is stealing your bandwidth. To prevent this, you can paste this into a file, upload it to the root of your website and then rename the file to .htaccess
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www.)?yourdomain.com [NC]
RewriteRule .(jpg|jpeg|png|gif|exe|zip)$ – [NC,F,L]
replace yourdomain.com with the name of your domain.com, yourdomain.net etc.
If you want to redirect the hotlinker to an image that shows you do not want others to hotlink to you – such as
Use the following statements in your .htaccess file but make sure you do not place the image on the site itself you do not want hotlinking from.
If you place the image on the domain that you are restricting hotlinking from, you will put the server into an endless loop. Use another domain to host this image from (as long it is one of your domains or you have permission to host the image there). You can use Photobucket, Image Shack, Picasa, Amazon Simple Storage Service and similar places where you can host images from – to host your no hotlinking image.
Next, use the following code in your .htaccess file
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www.)?yourdomain.com [NC]
RewriteRule .(jpg|jpeg|png|gif|exe|zip)$ http://www.anotherdomain.com/images/nohotlink.jpg [NC,R,L]
Replace yourdomain.com with the name of your domain.com, yourdomain.net etc. and replace http://www.anotherdomain.com/images/nohotlink.jpg with the path to another domain that hosts the image you want to use to show instead of the hotlinked image.
Afterwards, use the tools at http://www.htaccesstools.com/test-hotlink-protection/ to check to see if your file is hotlink protected. If you do not see your image after pasting the direct link to it, you know yours works!
Once again, I must reiterate:
Make sure you do not place the image on the site itself you do not want hotlinking from.
Popularity: 8% [?]
No related posts.
Related posts brought to you by Yet Another Related Posts Plugin.
§
Tags: bad, bandwidth, bandwidth stealing, hot, hotlink, hotlinking, imagelink, link, linking, no no, stealing
13 Comments »




November 7th, 2008 at 7:56 pm
thank u for your helpful article
i have try some trick but not working, now it’s working
November 8th, 2008 at 3:31 am
@minanube Thank you for your comment! I am very glad you found this article useful. I am also happy for you that it was able to help protect you from others doing the same to you (hotlinking) I wish there was an easier way.. I guess there are just so many that do not realize what they are doing when they DO hotlink!
November 9th, 2008 at 4:30 pm
i didn’t know that the secret lies in htaccess. this is a fantastic tip! thanks so much for sharing ^_^
November 10th, 2008 at 4:55 am
@techniqueal t. I am glad it helped! I really have had a LOT of success with it. It is really saving me a lot ! Some of the images that were being hotlinked from my site were over 1 meg big. Though that might not sound like much.. when one 1MB image is displayed a million times a month.. that is a gig of bandwidth I have to pay for.. then multiple that times 10, 20 or even 50 images.. and you can see it uses a lot of bandwidth. And, most providers only allow X amount of bandwidth a month before the user starts paying extra money!
On top of that, consider some companies limiting bandwidth every month. It seems to be a new trend. At the rate some people hotlink files.. they could use ALL my bandwidth in a month and I wouldnt even get to see the google homepage. Ok, so that is exaggerating.. it is not going to go THAT fast.. but it is the principle!
August 3rd, 2009 at 6:41 am
Hi
This is very useful. I have a spammer that has hotlinked to my Scritp in my CGI_BIN folder. What do I need to insert in the last line to stop a link to the script?
August 7th, 2009 at 7:01 am
What if I want to allow two domains to access images on my server…? Then what would be the code
August 8th, 2009 at 7:29 pm
Ok, I just want to say thank you for posting this info.
I have a blog that is with Blogger, in that blog is over 441 .zip files, I’m getting hotlinked like crazy.
I plan on switching to Wordpress very soon, I’ll use this setup (thanks).
When I setup my new Wordpress site, I’ll switch all of my old .zip files to include a single text file that will direct traffic to my new Wordpress site (LOL, that will fix them)! I’ll leave all my old images (hosted on Picasa) that they hotlinked to alone, so they won’t realize they are sending me their traffic, sorry If I sound harsh, but I’ve been racking my brain all day, looking for a way to stop the hotlinking.
So by them hotlinking to me (like crazy) they will be giving my new Wordpress site a nice little boost of traffic, when I first startup.
Again thank you for this post/info, you have gave me hope, & the nudge I’ve needed to actually move up to Wordpress.
Thanks,
PS. This does work with .zip files also, correct? Just want to double check before the Wordpress move.
August 12th, 2009 at 1:03 am
As long as you have zip in this last line
RewriteRule \.(jpg|jpeg|png|gif|zip|exe|tgz)$ http://ericawashere.com/images/erica-says-no-hotlink-my-files.jpg [NC,R,L]
this means it is denying hot linking to jpg jpeg png gif zip exe and tgz files
http://ericawashere.com/images/erica-says-no-hotlink-my-files.jpg [NC,R,L] This part sends it to a jpg that I made
if you want to see… http://ericawashere.com/images/erica-says-no-hotlink-my-files.jpg
August 12th, 2009 at 1:05 am
you can add as many domains you want
for example this would be two
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?aleeya.net [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?ericastjohn.com [NC]
RewriteRule \.(jpg|jpeg|png|gif|zip|exe|tgz)$ http://ericawashere.com/images/erica-says-no-hotlink-my-files.jpg [NC,R,L]
August 12th, 2009 at 1:07 am
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?aleeya.net [NC]
RewriteRule \.(jpg|jpeg|png|gif|zip|exe|tgz)$ http://ericawashere.com/images/erica-says-no-hotlink-my-files.jpg [NC,R,L]
putting your domain where i have aleeya.net would cover all images including your cgi bin as long as the cgi bin is under that domain
September 21st, 2009 at 12:24 pm
[...] Source: http://www.girlgeekette.net/internet-info/htaccess-how-to-stop-hotlinking/ [...]
October 16th, 2009 at 3:45 pm
Thank you A MILLION times for posting this!
It took me a bit of Google searcing to find your article, but it was definitely worth the search!
I’ve read some similar posts but I really needed an example to understand it.
Never tried editing my htaccess before, it’s been empty until now!
Now I can prevent all those pesky bloggers from using my images!
January 7th, 2010 at 10:52 am
If I can’t hotlink and image I would instead link to the site itself. But if everyone starts doing that won’t it take up a lot more bandwidth? Am I missing something here?