The Best Way to Block Image Hotlinking

"Image Hotlinking" is when another website embeds an image from your site (usually without permission).  This increases your bandwidth bill, is a potential security concern, and is generally a pretty rude thing to do.  To prevent this in Drupal, add the code below to your sites/all/files/.htaccess file:

# image hotlink protection
<IfModule mod_rewrite.c>
 RewriteEngine on
 RewriteCond %{HTTP_REFERER}     !^$
 RewriteCond %{REQUEST_FILENAME} -f
 RewriteCond %{REQUEST_FILENAME} \.(gif|jpe?g?|png)$           [NC]
 RewriteCond %{HTTP_REFERER}     !^https?://([^.]+\.)?domain\. [NC]
 RewriteRule \.(gif|jpe?g?|png)$                             - [F,NC,L]


Add new comment

This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.