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

Subscribe
Notify of
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
pascal
12 years ago

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


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

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

 

1
0
Would love your thoughts, please comment.x
()
x
The IT Development and Technology Mini Vault | MicroDevSys.com
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.