Header Shadow Image


Prevent Hotlinking and Missing Site Images

To prevent hotlinking, which is direct linking to another site's content such as images, videos, documents without actually storing them on your own hosting account often happens on the web and is generally frowned upon.  To prevent this, we include the following in our .htaccess file to prevent image / media hotlinking.  This is because the bandwidth taken up by hotlinking is incurred against the host that hold the media item and counts towards the remote source bandwidth.  Here's what a sample look like to protect against this on our site and can be customized towards any other site:  

RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?(mdevsys.com|microdevsys.com|microworkshop.com)(/)?.*$ [NC]
RewriteRule \.(gif|GIF|png|jpg|JPG|bmp|BMP|wav|mp3|wmv|avi|mpeg)$ http://www.microdevsys.com/IntroImages/BannerFlat-microdevsys.com.jpg[R,L]

There is a caveat to this.  If we were to setup something like http://forums.mdevsys.com, we would trigger this rule as well and all images on our forum would not load.  This is because of this clause in the condition:

(www\.)?

This indicates that www.mdevsys.com would work, but forums.mdevsys.com is not covered by the condition.  So we modify it to this:

(www\.|forums\.|tomkacperski\.)?

And so the modified rule would be:

RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.|forums\.|tomkacperski\.)?(mdevsys.com|microdevsys.com|microworkshop.com)(/)?.*$ [NC]
RewriteRule \.(gif|GIF|png|jpg|JPG|bmp|BMP|wav|mp3|wmv|avi|mpeg)$ http://www.microdevsys.com/IntroImages/BannerFlat-microdevsys.com.jpg[R,L]

And your images from http://forums.mdevsys.com will once again work as expected.

Cheers,
TK

One Response to “Prevent Hotlinking and Missing Site Images”

  1. thank you, it works for my site with Chrome, Safari, IE but not with Firefox, I still have access to the mp3 files

Leave a Reply

You must be logged in to post a comment.


     
  Copyright © 2003 - 2013 Tom Kacperski (microdevsys.com). All rights reserved.

Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 Unported License