How do I stop leachers from linking my content?

One quick and easy trick in Apache to block users from leaching your images (or other files) from your web space is with mod_rewrite; the rule I'm going to share with you today will block image leachers and file leachers from raiding your bandwidth.

Each site you wish to add will have its own line, and will be prefixed by "RewriteCond %{HTTP_REFERER} !"

Blocking Image Hotlinkers .htaccess entry:
Code
# Start UGN Specific Hosts #
RewriteCond %{HTTP_REFERER} !38.99.95.240 [NC]
RewriteCond %{HTTP_REFERER} !38.99.95.222 [NC]
RewriteCond %{HTTP_REFERER} !undergroundnews.com [NC]
RewriteCond %{HTTP_REFERER} !undergroundnews.net [NC]
RewriteCond %{HTTP_REFERER} !undergroundnews.org [NC]

# Start Affiliate Hosts #
RewriteCond %{HTTP_REFERER} !ubbdev.com [NC]
RewriteCond %{HTTP_REFERER} !ubbcentral.com [NC]

# Start Search Engine Hosts #
RewriteCond %{HTTP_REFERER} !google.com [NC]
RewriteCond %{HTTP_REFERER} !yahoo.com [NC]
RewriteCond %{HTTP_REFERER} !picsearch.com [NC]
RewriteCond %{HTTP_REFERER} !^http://aolsearch.aol.com [NC]

# Start defined files & redirect location #
RewriteRule [^/]+.(jpeg|jpg|gif|bmp|png|JPEG|JPG|GIF|BMP|PNG)$ - [F]


This will block all users linking to the file types ".gif", ".jpg", ".jpeg", ".psd", ".png"; they will receive a red X when trying to link to your graphics.

You can forward them to another graphic of your choosing as well by replacing the image rule at the bottom of the above example with:
Code
RewriteRule [^/]+.(jpeg|jpg|gif|bmp|png|JPEG|JPG|GIF|BMP|PNG)$ http://www.yoursite.tld/nofreelinking.gif [F]


You can use the above rules to also block hotlinking to files by using:
Code
RewriteRule [^/]+.(exe|com|swf|fla|mp3|mov|wmv|rm|ram|wma|zip|txt|bat|tar|rar|gz|tgz)$ - [F]


And you can additionally use it to block BOTH files and graphics with:
Code
RewriteRule [^/]+.(exe|com|swf|fla|mp3|mov|wmv|rm|ram|wma|zip|txt|bat|tar|rar|gz|tgz|gif|jpg|jpeg|psd|png)$ - [F]


The hosts section has separate sections for your site hosts (for sites with more than one domain), affiliate hosts (so you can allow your affiliates to grab your content), and for search engines (so Google images can grab copies of your files to show in an image search).
Posted on July 1st, 2007

Comments

( Posted)
Request a Quote
Please feel free to Request a Quote at any time.

By requesting a quote you allow us to adjust pricing for your product on a per-project basis. Note that most of the prices on our pricing page are just our "common" pricing and can vary on a per project basis. It will also allow us to add any per project discounts where we see fit (non-profit organizations, affiliations, etc).

If your "type" of project isn't listed in our menu's to the left, please Request a Quote; we can do much more than what is listed however building pages for it all would take a great while.
Financing Available
Hosting
We utilize StableHost for the hosting of our all of our VPS'. They're also #1 host that we recommend to every one of our clients, friends, and family. For more Web Hosting recommendations, please see our Recommended Hosts page!

StableHost Web Hosting

For EMail hosting we recommend G Suite (Formerly Google Apps and Google for Business).