How to Disable Hot Linking to Images

Roll up your sleeves and prepare to edit your .htaccess file.

Important Note:
Messing with your Web site or blog’s .htaccess file is very dangerous. Indeed, if you make an error, the entire site may stop working. Keep that in mind when using these instructions. I will not be held responsible for any problems that result from using this code.

Hot linking is when another Web site links directly to images or other files that reside on your Web server to embed them in their own Web pages or make them accessible to their own site visitors. For example, someone may like an image on your Web site that he/she wants to show off on his/her own. Rather than linking to the page on your site that displays the image, they might use the HTML IMG SRC tag to embed the image on their own site.

There are two problems with this:

  • In many cases, because the image actually appears on the other site, visitors are led to believe that the image belongs to that site’s owner — instead of you. Sometimes the other site owner might provide credit or even a link back to your site. But often times he/she does not. In my book, that’s image theft.
  • Because the image still resides on your server, each time the image is viewed on the other site, your server is required to serve up the image. That uses up your bandwidth. Obviously, if this happens a lot, you might see a slow-down in your site’s response time or your hosting company may begin to charge additional bandwidth fees. In other words, you’re paying to host images on someone else’s site.

The best way to stop hot linking is to modify your site’s .htaccess file to include code that prevents it. In researching this problem, I found several different collections of code. The one that I wound up using as a basis for my final code (shown below) can be found at “How to Disable Hot Linking” on the Online Marketing Blog.

Here’s my code:

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www.)?<em>mydomain.com</em>/.*$ [NC]
RewriteCond %{HTTP_REFERER} !google\. [NC] 
RewriteCond %{HTTP_REFERER} !search\?q=cache [NC]
RewriteRule .(jpg|gif|png|pdf)$ http://<em>myotherdomain.com/images/StopStealing.jpg</em> [R]

Here’s how it works:

RewriteEngine on

Enables mod_rewrite.

RewriteCond %{HTTP_REFERER} !^$

Allows requests made directly for the image without a referrer. You would include this line if you wanted to allow requests from browsers and other sources without referrers. (I commented out this line in my file, but may allow it.)

RewriteCond %{HTTP_REFERER} !^http://(www.)?<em>mydomain.com</em>/.*$ [NC]

Allows requests made from your Web site. Obviously, you’d replace mydomain.com with your domain.

RewriteCond %{HTTP_REFERER} !google\. [NC] 
RewriteCond %{HTTP_REFERER} !search\?q=cache [NC]

Allows requests made from Google and search engines. If you don’t want your images to appear in search results, don’t include these two lines.

RewriteRule .(jpg|gif|png)$ http://<em>myotherdomain.com/images/StopStealing.jpg</em> [R]

Prevents images with .jpg, .gif, and .png extensions from appearing on pages with any other referrer. Instead, it shows the image shown here.

If you don’t want to include the image, you can use this line instead to result in a broken image icon:

RewriteRule .(jpg|gif|png)$ - [F]

Keep in mind that using this approach will prevent images from appearing in feed readers, too, so it’s not a good idea if you share your images with others via RSS.

Of course, to add or modify a .htaccess file, you need to know how. That’s beyond the scope of anything I’ll ever write. These instructions assume you already have some idea of how to do this. If you want to learn more about using .htaccess to control access to your Web site, be sure to check out this tutorial.

One more thing…please don’t expect me to help you debug your .htaccess file. Believe me, I know only enough about .htaccess to be dangerous; you would be better off without my help. Good luck!

.htaccess Modifications Boost My FeedBurner Numbers

The fruits of my labor.

Yesterday, I spent a good part of the day updating my site’s .htaccess file to redirect requests for my WordPress-generated feeds to my corresponding FeedBurner feeds. This included the main feed for my site as well as individual category feeds for my Book Support categories.

I discussed why I wanted to do this in a previous article, “The Definitive Guide to Apache mod_rewrite,” which includes a quick book review of the book I found extremely helpful to complete this daunting (for me, at least) task.

The resulting .htaccess file included a few RewriteCond and RewriteRule statements to point most feed requests to my FeedBurner feeds. I say “most” because, for some reason, I couldn’t get one of the RewriteRule statements to work.

Having trouble understanding what the heck I’m talking about? Here’s a way to look at the situation:

Think of all of the incoming feed requests as a flow of water coming into my site. I don’t want that water in my site — I want it at FeedBurner’s site so I can measure it and ensure consistent outflow. My RewriteRule and Redirect statements are like pipelines, each of which gathers a specific flow of water and delivers it to FeedBurner. I need one more pipe to capture the last trickle of water coming into my site. I think I have the right pipe, but the water’s not flowing into it.

(Sometimes I really do get carried away with analogies.)

Anyway, this morning I checked my Feedburner subscriber numbers. After all, if I started sending FeedBurner more of my requests, there should be more subscribers, right? The result had me pleasantly surprised: I had about twice as many subscribers today as yesterday for my main feed. It’ll be interesting to see what tomorrow’s number looks like.

I also made some changes to the category feed links (those tiny orange icons in a post’s header) so they’re redirected to the corresponding Feedburner feeds. Of course, this was only for my Book Support category topics. I don’t have a FeedBurner feed for every category on my site, so I couldn’t redirect them all.

What’s the benefit of a FeedBurner feed? Two obvious things that I can see:

  • Feedburner can track the number of subscribers to a feed, so you can instantly and easily see how popular a feed is. It also provides a bunch of other stats to help you understand what subscribers are interested in.
  • Feedburner’s BrowserFriendly feature takes ugly feed code and turns it into a Web page. So if someone clicks a feed link, they get something they can actually read in their browser. Best of all, there are buttons near the top of the page that make it easy to subscribe with a bunch of different popular feed readers. This is a great feature to convert newbies into subscribers.

I’m not completely done messing around with .htaccess on my site, but I’m taking a break from it. Sometimes when I hit a block, the best thing to do is walk away for a while and come back to it. I’ll get that last pipe working — but not today.

Anyone interested in seeing the .htaccess commands I used? Use the Comments link to let me know and I’ll put them online in another post.

Reorganizing WordPress Categories

I do a little end-of-year cleaning.

I decided the other day that some of my blog’s categories were too similar to others (for example, Flying for Hire, Flying for Pleasure, and Flying Lessons) and that I wanted to trim down my category list to make room for new categories in the future. So I combined a few categories and added one.

When I combined Writing for a Living and Writing for Pleasure into one category (Writing), I did it the hard way: I edited all the posts in Writing for Pleasure to use the Writing for a Living category. Then I changed the Writing for a Living category’s Category Name to Writing and the Category Slug to writing. I renamed Writing for Pleasure as a new category called On Blogging with a category slug of blogging. This was extremely time consuming, since I had to modify each individual post and was working from home, with a miserable 256Kbps connection.

For the three flying categories, I decided to get fancy. I changed the name and slug of Flying for Hire, which had the most posts, to Flying and flying. Then I changed the default category (Options > Reading) to Flying. Then I deleted the Flying for Pleasure and Flying Lessons categories, clicking OK in the warning dialog that appeared for each one to allow the default category (Flying) to be assigned to each. This was certainly a faster way to get the job done, but it gave me quite a scare when the number of posts in the Flying category did not increase and the total post count decreased. Had WordPress actually deleted posts? I had to check the contents of that category to make sure I had posts from all three categories in it. I do, but the inconsistent count has me worried, so I don’t necessarily recommend doing what I did to combine categories. Ask me in a week or two and I’ll let you know what I think.

Of course, changing category slugs isn’t a good thing to do when you’re using one of the permalink options (Options > Permalink) to make “friendly” URLs. My changes affected five categories; any links to the old category slugs would break. So I opened my .htaccess file and added the following lines near the top:

Redirect permanent /category/weblog/writing-for-a-living/ http://www.aneclecticmind.com/category/weblog/writing/

Redirect permanent /category/weblog/writing-for-pleasure/ http://www.aneclecticmind.com/category/weblog/writing/

Redirect permanent /category/weblog/flying-for-pleasure/ http://www.aneclecticmind.com/category/weblog/flying/

Redirect permanent /category/weblog/flying-for-hire/ http://www.aneclecticmind.com/category/weblog/flying/

Redirect permanent /category/weblog/flying-lessons/ http://www.aneclecticmind.com/category/weblog/flying/

Keep in mind here that all of the categories I changed are actually subcategories of the Maria’s Weblog category, which has a slug of weblog. Each of these lines automatically redirect the old category URL to the new one. You can learn more about .htaccess at one of my favorite online sources: Stupid .htaccess Tricks.

The net effect of all these changes? Five categories have been combined into two and a new category has been created. My links should continue to work as they did.

Now let’s just hope I didn’t lose any posts or screw up that .htaccess file…

Redirects with .htaccess

I may have come up with a solution for the RSS errors I’ve been seeing.

When I combined Maria Langer, the Official Web Site* with my personal WebLog and LangerBooks.com, my book support site, into one site at www.aneclecticmind.com, I soon realized I had a problem. A bunch of people who were accessing the RSS feed for my old Mac OS X VQS book support site were still looking for it at the old address. Trouble is, it wasn’t there anymore. So these feed readers were looking for something they’d never find. And rather than give up and get on with their feed reader lives, they evidently kept looking, day after day, week after week. The people following the feed were probably either too overwhelmed by other content to notice my absence or had the silly idea that I just wasn’t writing anything new.

I discovered this, by the way, by checking the Users Online feature of my site. If I had a bunch of users online, I’d pop over to that page to see what they were looking at. I noticed that some of them were looking at my Oops! Page Not Found page. And when I pointed to the URL link, I saw that the page they were trying to get was the feed page for the Mac OS X books.

What could I do? I didn’t know. But the problem always bumbled around in the back of my mind. I figured I’d resolve it sooner or later.

Today, while waiting for a friend I’d taken to the doctor’s office, I killed some time listening to podcasts on my iPod. One of them was a podcast I’d only recently subscribed to: Podcasting Underground. In one episode, the host brought up a problem he’d experienced using redirects in his podcast feed. Although I didn’t have the same problem and his solution didn’t apply to me, it got me thinking. Redirects. Of course!

To those of you who don’t know, a redirect is an instruction that tells the visitor to Web content that the content isn’t available where he’s looking but is available elsewhere. It redirects him to the correct place.

There are at least two kinds of redirects — at least two kinds that I know about, that is.

One is extremely basic and uses an instruction in the head element of a Web page to send the visitor elsewhere, occasionally with a timer. Whenever you go to a Web page that says “We’ve moved to http://blahblah.com. Click this link if the new page does not appear automatically in five seconds.” That page has a redirect with a five second delay. It’s an easy redirect to create (if you have HTML knowledge) but it does waste time and effort by letting the visitor go to the wrong place in the first place. It also requires an HTML document at the wrong location. Not very smart, if you ask me, but it does have its purposes.

The other redirect requires rolling up the sleeves and editing the invisible .htaccess file that can live in a variety of places on a Web server, including the server’s root directory, a Web site’s root directory, or a specific directory within a Web site. This file can contain all kinds of instructions, as you can learn about in the Comprehensive Guide to .htacess or elsewhere online. (Just Google .htaccess and don’t forget the leading period or “dot.”)

The only instruction that interested me was the redirect command. It uses the format:

Redirect olddirectory/oldfile.html http://www.newsite.com/newdirectory/newfile.html

So I composed a command string that I think should work, stuck it in my .htaccess file, and resaved the file to my server. The new file location is set to the RSS feed for this entire blog. I figure they can always come back and change their subscription for the specific content they want.

Now it’s wait and see. I’ll keep peeking at the Users Online page to see if there are any people on the error page, then point to the URL to see what they were trying to find. If it’s the old RSS feed file, I’ll tweak my .htaccess entry accordingly. So far, I’ve only had to tweak it once…it looks like it might actually be working.

And if you know any other good online resources for .htaccess information, please use the comments link to share their URLs with readers.