View Full Version : How to use hotlink protection
D0gSoldi3r
11-03-2008, 08:26 PM
Hey guys i have alot of images which i know for sure people will try and steal my bandwidth, I've been having issues with Jpromoter (a joomla Component) and asking them for help only to find out this is a hostmonster issue (you might remember me talking about it 4 weeks ago here) what was happening was i was pulling out my hair because Jpromoter would not work and all my url's were broke and i could not find the cause and i only found out tonight the cause of my url's breaking was because everytime i used hotlink protection it tampered with my .htaccess file and added this on my .htaccess file
########## End - Rewrite rules to block out some common exploitsRewriteCond %{HTTP_REFERER} !^http://funny-s.com/.*$ [NC]
This line of code sort of somehow breaks Jpromoter, how jpromoter works is takes that long url from joomla that makes no sense and turns it into a sentence relating to the content. And each time i mess around with hotlink protection every single url breaks down, i only found this out when i compared my old .htacccess file to the current one and found massive issues with hotlink protection.
Is there any method i could use without using hotlink protection to protect my bandwidth.
sjlplat
11-03-2008, 09:27 PM
I build my own hotlink protection with .htaccess. Here's a brief explanation how it works:
Turn on URL Rewriting.
RewriteEngine on
Allow blank referrers.
RewriteCond %{HTTP_REFERER} !^$
Allow all domains that should have access to your images.
RewriteCond %{HTTP_REFERER} !^http://(www\.)?yourdomain.com/.*$ [NC]
Redirect traffic from domains that are not allowed to access your images.
RewriteRule \.(jpg|gif|bmp|png)$ http://www.yourdomain.com/path/to/replacement/image.jpg [R,L]
D0gSoldi3r
11-03-2008, 11:01 PM
Say for talking sakes i wanted to allow more than 1 site how would the code go below for several sites.
RewriteCond %{HTTP_REFERER} !^http://(www\.)?yourdomain.com/.*$ [NC]
pghcollectibles
11-04-2008, 05:37 AM
im only answering this in case it helps you before sjlplat replies as i dont know the subject well, but i believe you make a new line for each domain:
RewriteCond %{HTTP_REFERER} !^http://(www\.)?domain1.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?domain2.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?domain3.com/.*$ [NC]
however i dont know the answer to this but it is important for this topic. what if you wanted to allow just the domain (without www) or (seperate code for each please) to allow any subdomain of a domain ie: home.domain.com
Falcon1986
11-04-2008, 07:23 AM
That is correct, 'pghcollectibles'. Just add a new line for each domain you want to permit hotlinking.
Furthermore, this portion of the rule takes care of a www or non-www URL:
(www\.)?
Here is an example of permitting multiple domains, with or without www or https, for access of a series of file extensions or a particular file.
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yourdomain.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yourdomain2.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ file.gif [NC,R,L]
htaccesstools.com (http://www.htaccesstools.com/)
D0gSoldi3r
11-17-2008, 01:02 PM
Well i haven't had much time recently to try that code out but i had time today and it didn't work for me, i added this code in my .htaccess file
###########Hot-Link-Protection#############
########## This is to stop from stealing my bandwidth
#
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?funnystash.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?funny-s.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ /ExternalImages/hotlink.gif [NC,R,L]
#
########## End - Hotlink protection
but if i try and hotlink with the tags i'm still able to steal bandwidth from my site :(
----------> http://www.funnystash.com/images/rsgallery/original/Ghost-buster-dance-Animated-GIF.gif
Falcon1986
11-17-2008, 04:13 PM
Try the following...
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?funnystash\.com(/.*)?$ [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?funny-s\.com(/.*)?$ [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ /ExternalImages/hotlink.gif [NC,R,L]
sjlplat
11-17-2008, 11:46 PM
###########Hot-Link-Protection#############
########## This is to stop from stealing my bandwidth
#
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?funnystash.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?funny-s.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ http://www.funnystash.com/ExternalImages/hotlink.gif [NC,R,L]
#
########## End - Hotlink protection
Your rewrites are missing some critical components.
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?funnystash.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?funny-s.com [NC]
should be
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?funnystash.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?funny-s.com/.*$ [NC]
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.