htaccess

Using .htaccess To Stop Hotlinking

Recently, a few of my photos started ranking highly on Google Image Search for terms like "cat" or "geese". An unfortunate side effect of this new found popularity has been dozens of people hotlinking my images on their websites without permission.

At first, I didn't really mind, but it reached a point where 9 out of 10 hits on my website were for hotlinked images. So I decided I had to do something about it.

The solution was to write an .htaccess file to block hotlinks, and place it in my photos directory. The code looks something like this:

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(.*\.)?blamcast.net [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(.*\.)?ppalinks.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(.*\.)?drupal.org [NC]
RewriteRule \.(jpeg|jpg|gif|png)$ http://example.org/bad.jpg [NC,R,L]

... Read the rest of this post!

Posted by John on 2007-11-02

How To Block Bots, Ban IP Addresses With .htaccess

htaccess book
The ultimate guide to writing advanced .htaccess files!

Got a spambot or scraper constantly showing up in your server logs? Or maybe there's another site that's leeching all your bandwidth? Perhaps you just want to ban a user from a certain IP address? In this article, I'll show you how to use .htaccess to do all of that and more!

... Read the rest of this post!

Posted by John on 2007-06-23
Syndicate content