Prevent Image Hot Linking on Zeus Web Servers
A client asked me to do so work on their website to prevent people from hot linking their images, as they were using up most of their bandwidth allowance and had just been dealt a hefty bill, for extra bandwidth used.
Straight away, I said no problem. 2-3 lines in your .htaccess file should do it. WRONG!!. Their host was using a Zeus webserver, and although it does implement some of Apache’s .htaccess directives, its rewrite rules are totally different.
I started scouring the internet, for apache to zeus converters, but the ones I did find and use didn’t seem to work. I finally had to bite the bullet and learn how to do rewrite rules with zeus.
By default, Zeus rewrite rules are added to a rules section in the Zeus web admin control panel. My client was using shared hosting so I had no access to this control panel. Luckily their hosts did have a setup that allows you to add a script to the web root, which will get read just like an .htaccess file does. This script is usually called rewrite.script.
Below is a copy of the rewrite script I wrote for them to prevent people hot linking their images. Just replace the “yourdomain” section with your own domain. Also this rule is only preventing hot links to gifs and jpegs, to prevent more add them to the line beneath the comment “# Match image urls”
RULE_0_START:
# Match image urls
match URL into $ with \.(gif|jpe?g)$
# If its not an image then skip the rules
if not matched then goto RULE_0_END
# Save the referer
set SCRATCH:COND = %{IN:Referer}
# Check the referer is not empty
match SCRATCH:COND into % with .
# If it is empy skip rules
if not matched then goto RULE_0_END
# Save the referer again
set SCRATCH:COND = %{IN:Referer}
# check it matches this domain
match SCRATCH:COND into % with ^http://(www\.)?yourdomain\.com/
if matched then goto RULE_0_END
set RESPONSE = 403
set BODY = Access to this page is denied
goto END
RULE_0_END:
I have sinced used this script on several other sites with 100% success.

December 13th, 2008 at 1:57 pm
Nice.
1. Why do you save the referrer twice?
2. Does this fail if the referrer is faked?