Posted By

josephknight on 07/05/10


Tagged

images htaccess security rewrite


Versions (?)

Who likes this?

6 people have marked this snippet as a favorite

NARKOZ
seloh77
kubaitis
trancecoder
jeredboxman
tomenjr


htaccess - disallow linking to images from outside your site


 / Published in: Apache
 

Replace "mysite" with your own and this will block access to sites attempting to link to your images. Note, it's not necessarily always a bad thing for people to link to your images. If you run a blog, portfolio, or sales gallery, etc, you may actually want your images to show up in google image search results and the like. Careful that you're not blocking your goals along with the images. Make sure this script is for you.

  1. RewriteEngine On
  2. #Replace ?mysite\.com/ with your blog url
  3. RewriteCond %{HTTP_REFERER} !^http://(.+\.)?mysite\.com/ [NC]
  4. RewriteCond %{HTTP_REFERER} !^$
  5. #Replace /images/nohotlink.jpg with your "don't hotlink" image url
  6. RewriteRule .*\.(jpe?g|gif|bmp|png)$ /images/nohotlink.jpg [L]

Report this snippet  

You need to login to post a comment.