back       next

Disable Leeching of Images with mod_rewrite

You will need to create a ".htaccess" file with the below contents in your web/public_html directory to prevent leeching of images.

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://yourdomain.com.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.yourdomain.com.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://yourIP/.*$ [NC]
RewriteRule .*[Jj][Pp][Gg]$|.*[Gg][Ii][Ff]$|.*[Pp][Nn][Gg]$ http://yourdomain.com/error.gif [R,L]

It prevents all images from being hotlinked and if someone tries anyway the image "error.gif" is shown. So you will also need to create a cutom "error.gif" and upload it to your main website directory.

Post new comment

  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.