Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I avoid bandwidth theft?

.htaccess

How can I avoid bandwidth theft?

by  danomac  Posted    (Edited  )
What is bandwidth theft?

Bandwidth theft occurs when others hotlink to files directly on your site, when you do not want them to. A common occurance for this is linking to your images, sound, or pdf files, as an example.

A common example is web forums. Most forums allow you to host avatars (these are small images that users can associate to their nicknames) directly on your website. When you do this, what's to stop the user from using the avatar on your server on other web forums?

How can I stop bandwidth theft?

Fortunately, you can use a .htaccess file to do this. Copy the example below into the directory where your images/documents are:

Code:
SetEnvIfNoCase Referer "^https?://(www\.)?example.com/" ok=1
SetEnvIfNoCase Referer "^$" ok=1
<FilesMatch "\.(gif|png|jpe?g)$">
   order allow,deny
   allow from env=ok
</FilesMatch>

All you need to do is change two things:

1. Change the 'example.com' above to your domain. Do not remove anything else though! The (www\.)? makes the www part optional in your domain name. As it is in the example, www.example.com and example.com will be allowed access.
2. Change the <FilesMatch "\.(gif|png|jpe?g)$"> if necessary. In the example, 3 common graphic formats are caught (note that both jpg and jpeg are caught.) As an example to add pdf files to the restriction use <FilesMatch "\.(gif|png|jpe?g|pdf)$">.

Save your .htaccess and it should work. The images will appear as a broken link in browsers.

Note: This will not stop someone from directly typing the URL in a browser! It has to be a link pointing to your website from another domain!
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top