How to use .htaccess to stop image hotlinking

Valic —  January 9, 2013 — Leave a comment

You can stop others from hotlinking your site images by placing a .htaccess  file in your website main directory:

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)*$ [NC]
RewriteRule \.(gif|jpg|png)$ [R,L]

  1. The first line of the code enables the rewrite.
  2. The second line will block any website other than your own.
  3. The No case [NC] code will match the url regardless of being in upper or lower case letters.
  4. We allow empty referrals on the third line.
  5. The last line matches any files ending with the extension gif jpg and png. The hotlinked image will be replaced by the image specified here. You can also use here a link from another domain.


Posts Twitter Facebook

Editor in Chief at Debian-Tutorials, Linux enthusiast.

No Comments

Be the first to start the conversation.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.