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).


I am a Web Development Contractor, I do not work for UBBCentral. I have provided free User to User Support since the beginning of these support forums.
Do you need Forum Install or Upgrade Services?
Forums: A Gardeners Forum, Scouters World
UBB.threads: UBBWiki, UBB Styles, UBB.Sitemaps
Longtime Supporter & Resident Post-A-Holic
VNC Web Services: Code Modifications, Upgrades, Styling, Coding Services, Disaster Recovery, and more!