htaccess - disallow linking to images from outside your site


/ Published in: Apache
Save to your folder(s)

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.


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.