leihu home

Links to Me Will be Foresaken

imagined by: James Mathias

One of the most annoying things I run across when running a web-site is the theft of bandwidth, my bandwidth. This is most commonly done through the direct—or hot, if you will—linking to images on my server. The perpetrator is usually someone who thinks that all Internet content is free to use as they see fit. Unfortunately for me and you, we get stuck with the bill. There are some very simple ways to prevent this, unfortunately there is no ultimate solution that will prevent it entirely all the time. I’d like to present some basic solutions to keep a lid on heavy hot linking.

The old “Image Switch”

This is most likely the simplest method, yet it lacks automation and also requires you to make changes to your web-site directly. With this method you simply remove the hot linked image or replace it with something that gets the point across that you don’t appreciate being hot linked. The draw back is then you have to go through your entire web-site and repair all the broken links to the (old) image in question, because you’ll have to rename the real image to something else. I think this is a fine method if you have only a few images and a couple of hot linkers, but when you start getting a lot of images and a lot of illegitimate requests this method fails due to it’s heavy upkeep. My main complaint is that it requires you to change valid information architecture just to deal with a few ne’er-do-wells.

.htaccess to the rescue?

This method is better, though not ideal and still requires some upkeep. It may be more difficult for non-programmers, but that’s why I’m writing this down isn’t it? Also this method requires and Apache/UNIX server with mod_rewrite installed and enabled. With this method you can choose two routes “whitelist” or “blacklist” racial and good/evil connotations aside these two types of lists are different but the same.

The whitelist basically tells the server, only accept image requests deriving from these “good” domains. Whereas the blacklist tells the server, accept all image requests except from these “bad” domains.

A whitelist can be a quick and easy way to stop hot linking, but it has a couple of side effects, especially if you want to redirect the requests to a snarky image replacement. The reason a whitelist doesn’t work well is with RSS feeds you can recieve a lot of legitimate requests for images contained within your feed. You may also have advertisment banners that you allow people to directly link to. Now with a whitelist, you will shut out RSS feed readers entirely, but you could add any legitimate domains for banners and buttons, but that could get tedious as you get more popular.

Blacklists on the other hand can be a bit more maintenance free, as they will only block specific requests, for instance, I find a ton of folks over at myspace hot linking to my photos and illustrations, so I place the line;

RewriteCond %{HTTP_REFERER} ^http://(www.)?myspace.com/ [NC,OR]

In my .htaccess file which basically says do not allow any direct or hot linking from myspace.com. Of course there are some other lines you’ll want to put in there to get it to work which I’ll discuss in a second, but it’s important to remind you that you’ll need mod_rewrite installed and enabled on your server for this method to work properly.

Creating a .htaccess file

Just open a text editor and type in;

RewriteEngine on

This line initiates the rewrite engine so that the server will pay attention to the rest of what we want to tell it. Next you want to give the server instructions on what to allow/disallow. For whitelists you use the following line;

RewriteCond %{HTTP_REFERER} !^http://(www.)?YOURDOMAIN.tld/.*$ [NC]

This tells your server to only allow requests from referrers that match YOURDOMAIN, of course you’ll change the YOURDOMAIN to your actual domain name, and the .tld to your top level domain extension .com, .net, .tv etc… You may add other lines to cover other domains you may have or any domains you want to allow requests from.

For blacklists you write the condition like this;

RewriteCond %{HTTP_REFERER} ^http://(www.)?myspace.com/ [NC,OR]

This does the same thing as a whitelist, but in reverse, it allows all requests except ones coming from the listed domains. I prefer blacklists, as they tend to require less upkeep, just need to add a new restricted domain once in a while when they come up. You can place as many domain lines in either list as you want. After the list you need to tell the server which file types you want to prevent direct or hot linking to.

To accomplish this use the line;

RewriteRule .*.(jpg|jpeg|gif|png|bmp)$ http://www.1lotus.com/images/robber.gif [R,NC]

Ok, this is a little more complex but still very simple, the first part of the line;

.*.(jpg|jpeg|gif|png|bmp)$

Says any file with the extension .jpg, .jpeg, .gif, .png or .bmp will be redirected to alternate content. If you want to add additional extensions you can easily do so, just separate each extension with a “|” (the pipe) character, so let’s say I want to stop direct linking to .pdf’s as well, here’s how I would add those in;

.*.(jpg|jpeg|gif|png|bmp|pdf)$

Now the second part of our line;

http://www.1lotus.com/images/robber.gif [R,NC]

Tells the server where to send requests for the images and other media being made by domains on the blacklist or not on the whitelist. In my case I send the perps a pretty snarky and slightly asshole-ish image replacement to get the point across. I know, it’s bad, but I’m really tried of it.

To recap the .htaccess method I have explained—hopefully clearly—here, your .htaccess file should contain the following;

RewriteEngine on Initiates engine
RewriteCond %{HTTP_REFERER} ^http://(www.)?myspace.com/ [NC,OR] for blacklists OR
RewriteCond %{HTTP_REFERER} !^http://(www.)?YOURDOMAIN.tld/.*$ [NC] for whitelists
RewriteRule .*.(jpg|jpeg|gif|png|bmp)$ http://www.1lotus.com/images/robber.gif [R,NC] defines allowed/disallowed extensions and where to send the request.

Then just save the file as .htaccess, and upload it to the root directory of your web-site, usually where your main index.ext file is.

One thing to mention, you may only have one .htaccess file in each directory, so if you already have one that handles friendly urls or error redirect you can add the above code directly to the bottom of the file, just leave out the line;

RewriteEngine on As it should already be in the file elsewhere, and you only need to initiate the engine once.

Other Options?

Now there are other more complex options that would not require mod_rewrite or an .htaccess file. For instance you could use PHP or ASP to purposefully give your images false urls then do a little check to make sure the request for the image is coming through the script and not directly to the image. This is a small example but, it gives you an idea of what can be accomplished. I personally have good success using .htaccess.

If anyone has any suggestions to help make this information better or more clear, I would love to hear it. Thanks for reading I hope you enjoyed it.

More of the Same

10 recent “Developmentally Able”


hung, orgyen yul-kyi nup-chang tsham
pema kesar dong-po la
ya-tshen ch’og-ki ngodrup nyey
pema jugne zhey-su trag
khortu khadro mangpo kor
khyed-kyi jeysu dag-drub kyee
chin-kyee lab-ch’ir shegsu sol

guru pedma siddhi hung

your comments

12 comments





You know the score, keep it clean and on topic. “Spammers” & “trolls” are decimated on sight.

 

Bonita in Pink

Ohhhh man, I’m sorry this happens to you. Usually this happens to talented people like yourself. LOL No, seriously. I never get that. But then again, you create illustrations and stuff, I don’t.

I hate stealers like that. If I saw someone using my pictures or my face on something of theirs, all hell would break loose!

I wish I had other suggestions but eh! I don’t know crap about stuff like that. I disable hotlinking from my cpanel. It has an option to only enable certain domains [that I chose] to have a right to hotlink. They usually are my subdomains and stuff like that.

Good Luck beating these hotlinkers. They need a good cyber kick in the ass.

James Mathias

Hi Ana,

Yeah it’s frustrating to say the least. cpanel does have a built in ht link blocker section, but it just writes out similar code to what i’ve given here, but it does overwrite anything else in your .htaccess, and it can write sloppy regex, but it’s a good fit for non-programmers to quickly fix a giant problem.

Colin D. Devroe

What images are they thieving?

James Mathias

Mostly my illustrations, but some of Amy’s photos as well.

Bob

I liked the hotlink protection idea from a list apart…

A list apart hotlinking article

Although, i do like the replacement image thing (your robber image is amusing)… so maybe i’d combine both.

Wilhelm Murdoch

I think the best example of the old ’Image Switch’ is the Goatse incident from post 9/11 from Tribalwar.com. Google it, ’twas the funny.

I know.. I WAS THERE!111

James Mathias

@bob, yeah I saw that article after I’d already come up with this solution, so I decided to ignore it as if it didn’t exist, so I don’t feel like I wasted my time.

@wilhelm, any campaign that utilizes a picture of a guy stretching his asshole to the limit is not to be qualified as the “best evar” of anything, sorry.

Brian

Can the .htaccess file be modifided to only allow DIRECT links from particular urls/domains, etc …
I would like to run a member site on one server, and only allowed verified members to stream from another server if the link comes from a URL that you could not be using if you weren’t logged in to the member area. …. and no … this isn’t porn!

James Mathias

Hi Brian, Yes, use the Whitelist technique I have explained.

Onels4

Thank you for this article, the blacklist technique is very useful, and most sites only consider the whitelist system.

This was exactly what i needed.

James Mathias

No problem Onels4.

Glad you found it useful.

Uivuphar

Best Site Good Work gay escorts in san antonio 8( tucson summer internships for teenagers cnd

add comment

12 comments