Using .htaccess to Prevent Bandwidth Theft

Every once in a while Google Analytics will turn up a peculiar behavior where you can tell someone is linking directly to an image hosted on your Web server. Sometimes it can be for good reasons like giving you credit for a project, or make sure files are synced up (cross-domain projects); but it’s usually just out of ignorance or laziness (or myspace).
Either way, hotlinking images like that steals your bandwidth and can effect the performance of your server. So you want to stop it.
There are a few ways you can do this; some people output a special image to a bandwidth thief that says something like “Stop stealing my images”. I don’t like that mainly because you’re intentionally degrading your bandwidth to teach someone a lesson about hotlinking? Bleh.
I prefer using a 403 error, it works just as well in my opinion, and gets the point accross.
.htaccess code
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?csskarma\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule .*\.(jpe?g|gif|bmp|png)$ - [F]
Put that in your .htaccess file (in your root directory). If you don't have an .htaccess file, just create an empty file in the root and name it ".htaccess". Then put this code in there and you'll be good to go.
Don't forget to change out "csskarma" for your web site. You'll definitely notice if you forget that bit.
What's going on
Turn on the rewrite condition:
RewriteEngine On
Match any request for csskarma.com (NC means "no case" it will match upper or lower case requests):
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?csskarma\.com/ [NC]
Allow empty requests, these are harmless and often 404 errors anyway
RewriteCond %{HTTP_REFERER} !^$
Replace the stolen image with a 403 "forbidden" error
RewriteRule .*\.(jpe?g|gif|bmp|png)$ - [F]
You can leave a response, or trackback from your own site.
« Web Standards and the Shower Curtain | Analyzing Home »
|
Comments (8)
|
Trackbacks & Pingbacks (2)
-
Cheap phentermine….
Cheap phentermine by phone. Cheap phentermine. Phentermine cheap. Cheap phentermine pay cash on delivery. Cheap phentermine cod. Cheap phentermine diet pill….
-
hi guys…
hi guysI would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well and i have start my own blog now, , thanks for your effort…
Leave a Reply



Can you explain a little bit about what those rules are doing? I use htaccess files on most of my sites just to make sure site.com and http://www.site.com and site.net and all that all go where I want them. But I’ve never used it with images like this.
Sure thing, I’ll update the post
I suppose my question is then: On my own personal website, I have a folder that I use for hosting images that I post around the web (in other blogs that I write in, or just to host an image so I can link to it in tweets or whatnot).
So this technique described above would prevent me from doing this, yes?
I suppose, until my bandwidth is seriously compromised by people directly linking my images (it happens a bit now), I’ll just let it slide.
it will prevent people from displaying images that are hosted on your domain, but not just being linked to. You can still link to them in tweets and whatnot.
You can also turn off the rewrite condition in that folder so those images and be freely distributed.
Or you can remove an image type from that last line, like “png”, that should open up png linking, but still block all the others
if you were going for a .co.uk TLD woud you put
)?csskarma\.co\.uk/
or
)?csskarma\.co.uk/
I’ve never tried it, but my gut tells me you have to escape the extra dot like:
)?csskarma\.co\.uk/
Yet another reason I enjoy working on Apache servers. No .htaccess in ISS/Windows environments.
arisaka mexican markings
affordable catterpillar skidders
ami cusack naked
10 examples of simile lesson
abang gian
sanja stojanovic porno
worlds prettiest pussies
angelina jolie sex pics legolas
12 line rhyming poems
14 line sonnet poem examples
9trey blood knowledge
alexa chung fakes
98 ss s10 specs
aj wright department store in chicago
2008 nanda list financial
8 ball gang knowledge
55 gallon upright bbq smoker plans
angelique morgan nude
1989 chevrolet silverado fuse layout
130 grain 270 wby elk