Stop those hotlinking SOBs with .htaccess.

Stop those hotlinking SOBs with .htaccess.

Is your bandwidth meter spinning like a top, but your page views just aren’t where you think they should be for all that “traffic”? It’s possible that you, my friend, are a victim of bandwidth theft due to hotlinking. Hotlinkers are dirty SOBs who steal your bandwidth by streaming your graphics, videos and/or music files onto their web site(s) directly from yours. Luckily daddy has a relatively simple solution to fix all the badness for you.

While there are a few options you have when you want to deal with hotlinkers, I’m going to demonstrate the easiest and often best suited solution: displaying an alternate graphic instead of the one that the hotlinkers are stealing from your web site. If you’d like more options or want to do something different feel free to leave a comment below and I’ll answer as best as I can.

Now for the fun stuff. In the root of your blog’s web space, find and download (or create, if necessary) the .htaccess file. After you have a local version, copy and paste the following (and we’ll get into why some of the text is in bold in a moment) into the very beginning of the file:

.htaccess file

#   HOTLINK STOPPER
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?example\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?bloglines\.com/ [NC]
RewriteRule .*\.(jpe?g|gif)$ http://yourothersite.com/hotlink.jpg [R,NC,L]

If you don’t copy+paste the text above into the beginning of your .htaccess file you may run into problems if you break something that already exists, so please use caution. Also, don’t let all the mumbo-jumbo scare you off. It’s pretty simple stuff. In fact, there are only six lines, and I’ll walk you through what each one does.

  1. # HOTLINK STOPPER

    This line is just a comment (delineated by the # at the beginning of the line) to let you know what this section of your .htaccess file is for. You can comment out any line by prepending it with a # symbol.

  2. RewriteEngine On

    Turns on the rewrite engine in Apache. Without this, none of the rest of the changes are necessary. Or possible.

  3. RewriteCond %{HTTP_REFERER} !^$

    Sets a condition for the rewrite engine to ignore anyone with a blank referer. Don’t worry about the !^$, it’s a regular expression, or “regex”, and it works when looking for a blank referer. And yes, that’s spelled correctly… for Internet purposes, anyhow. If you’re interested in the details, read up on how a referrer came to be a referer.

  4. RewriteCond %{HTTP_REFERER} !^http://(.+\.)?example\.com/ [NC]

    Sets a condition for the rewrite engine to ignore anyone that doesn’t have the domain example\.com in their referer. Replace the example portion with your blog’s domain name, but make sure that if you’ve got a .org blog that you keep the backslash in from of the period, otherwise the regex will break.

  5. RewriteCond %{HTTP_REFERER} !^http://(.+\.)?bloglines\.com/ [NC]

    Sets a condition for the rewrite engine to ignore bloglines.com. This line is optional, but I kept it in this example since Bloglines is a pretty popular RSS reader, and you’re probably going to want your readers who use it to see the pictures on your server.

  6. RewriteRule .*\.(jpe?g|gif)$ http://yourothersite.com/hotlink.jpg [R,NC,L]

    Here’s where the fun begins. This line sets up a rule that will server any graphic (in this case a .jpg or .gif file) that is not ruled out from the conditions above to the file http://yourothersite.com/hotlink.jpg, thereby circumventing those damned, dirty apes hotlinkers. To add more file types, just add a pipe (“|”) character after gif and the extension (like a png) and you’re good to go.

    A word of caution: do not use a graphic that is on the domain that you are trying to dissuade hotlinkers from using as you’ll cause an infinite loop and in some cases may actually take down your own web server. I’ve seen it happen, and it ain’t pretty. I suggest you set up a free blog account somewhere, such as wordpress.com, and add your hotlink graphic there.

That’s pretty much it. All you have to do now is upload your new hotlink.jpg graphic and your .htaccess file and you’re good to go. If you’ve done everything right then the days of your bandwidth being stolen by hotlinkers should be coming to a close.

Comments

  1. GuessNo Gravatar says:
    Ready for a blast from the past bub? I worked with you, I drank with you, and I watched your wife in several community theater shows (Something Happened… and Nunsense? I think) Who am I? D’OH!!! My name is REQUIRED??? That hardly seems fair….
  2. JonNo Gravatar says:
    You almost got me, CRAIG, but The “bub”, “drink”, and “work” comments all worked their mojo. And then your email address clinched it for me. LOL! How the hell are you? I’m shooting you an email later tonight so we can catch up. :)
  3. JohnNo Gravatar says:
    Bandwidth is cheap and those hotlinked images end up looking like some of my best backlinks in Yahoo SE! Of course, the bandwidth might not be so cheap if we’re talking about high resolution photography as opposed to some saved-for-web charts or something…

Trackbacks

  1. [...] Confused? Blink. Blink. If you need help, call THIS awesome dude!  Halfbrown [...]
  2. [...] Stop those hotlinking SOBs!! Halfbrown.com [...]
  3. [...] Those hotlinking SOBs!!  Stop them!  Halfbrown [...]
  4. [...] Stop those hotlinking SOBs!  Halfbrown [...]
  5. [...] Stop those hotlinking SOB's NOW!  HalfBrown [...]

Speak Your Mind

*