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:
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.
-
# HOTLINK STOPPERThis line is just a comment (delineated by the # at the beginning of the line) to let you know what this section of your
.htaccessfile is for. You can comment out any line by prepending it with a # symbol. -
RewriteEngine OnTurns on the rewrite engine in Apache. Without this, none of the rest of the changes are necessary. Or possible.
-
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. -
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?example\.com/ [NC]Sets a condition for the rewrite engine to ignore anyone that doesn't have the domain
example\.comin their referer. Replace theexampleportion 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. -
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.
-
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, dirtyapeshotlinkers. To add more file types, just add a pipe ("|") character aftergifand the extension (like apng) 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.
A 6-Pack of Mac OS X Terminal Tricks.
I've been a proud Apple Switcher since 2006, but it took me a while to take all of my (not so) secret Windows knowledge and learn all new tips and tricks on the Mac. Being able to become as efficient in the world of Apple as I was with Windows didn't take as long as I thought, but it did have its bumpy parts.
Because of that, and my natural tendency to share knowledge, I've compiled a list of fun tips and tricks in Terminal (i.e. command-line stuff) that I've learned over the last few years. By no means did I discover these on my own... they are a compilation of OSX tips that I’ve found online or from friends with much more Mac knowledge that I.
-
Show all files, even system files, in Finder:
Open Terminal and type "
defaults write com.apple.Finder AppleShowAllFiles YES".Hold down the Option key and click on the Finder icon in the Dock and press Relaunch. You may have to wait a second or two for the relaunch option to display.
This one is a life saver for me. I hate not being able to see all files, so this is a must in my Mac machines.
-
Show full file paths in Finder:
Open Terminal and type "
defaults write com.apple.finder _FXShowPosixPathInTitle -bool YES".Another must-have! There are so many useful reasons to see the full file path in Finder, I don't get why it's not on by default.
-
Change the default (PNG) file format for screenshots:
Open Terminal and type "
defaults write com.apple.screencapture type EXTENSION", whereEXTENSIONcan be any of the following: BMP, GIF, JPEG-2000, JPEG, PDF, PICT, PNG, PSD, SGI, TGA, or TIFF.Don't get me wrong, I love PNGs, but sometimes you want a JPG and don't want to crack open Photoshop or some other graphics tool to do it.
-
Securely delete files from a drive:
Open Terminal and type "
diskutil secureErase freespace 3 /Volumes/DRIVE" whereDRIVEis the drive you want to securely delete.If you’re not comfortable using the command line, perhaps you should skip this one... it can be a dangerous tool in the wrong hands.
-
Create your own audio book with your Mac's default voice synth:
Open Terminal and type "
say -o AUDIOBOOK.aiff -f FILE.txt", whereFILE.txtis the path to a text file you want read.My kids love this one because they think there's a robot inside my MacBook Pro that is reading to them.
-
Force Apple Mail to show plaintext vs. HTML email:
Open Terminal and type "
defaults write com.apple.mail PreferPlainText -bool TRUE".I love HTML, but HTML email is, more often than not, a huge annoyance. I turn it off whenever possible.
I hope you've enjoyed these Mac OSX tips and tricks. If you have any that you feel are a must-have, or if you know of another way of doing any of the above, please let me know in the comments for this post.