Prevent Image Hot Linking from Apache Web Servers
Nov.24, 2010 in
Web Developement
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.
1 2 3 4 5 6 | 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 referals 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 referals from google cache
The final condition allows blank referals
Finally the rewrite rule rewrites any request for images to an image hosted on imageshack.us





Leave a Reply