jump to navigation

Prevent Image Hot Linking from Apache Web Servers May 14, 2011

Posted by Tournas Dimitrios in Uncategorized.

If you are getting stung by large bandwidth bills because someone is hot linking your images, copy the following lines in to your .htaccess file.

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?yoursite\.com/ [NC]
RewriteCond %{HTTP_REFERER} !google\. [NC]
RewriteCond %{HTTP_REFERER} !search\?q=cache [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule .*\.(jpe?g|gif|bmp|png)$ http://img249.imageshack.us/img249/2806/hotlink.gif [L]
  • The first condition only allows referrals from your site (replace yoursite\.com with your own domain)
  • The second condition allows Google to link to the images, allowing the use Google Image Crawler
  • The third condition allows referrals from google cache
  • The last condition allows blank referrals
  • Finally the rewrite rule rewrites any request for images to an image hosted on imageshack.us


No comments yet — be the first.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s