I use this as anti-hotlink protection for images. example.com is the domain which is allowed to hotlink images while all other domains are denied. This code also allows direct requests to image files using a browser's URL bar, but not hotlinking from another site.
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://example.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://example.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.example.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.example.com$ [NC]
RewriteRule .*\.(.*.*.*gif|jpg|jpeg|png|bmp|tif|tiff)$ [url]http://example.com/403.shtml[/url] [R,NC]
This example blocks entire file extensions. As an alternative, does anyone know how to change the info in the last line of this so that it will block hotlink access to a specific file such as example.jpg or even example.php?