PDA

View Full Version : htaccess hotlink prevention dual action?


bdl
01-23-2010, 05:21 PM
Is it possible to have different actions based on the referrer? What I'd like to do is prevent hotlinking on all images on our domain, but from a specific domain (e.g. ebay.com), I want a different action. Let's say the normal action is to simply force a 403, if coming from a different referrer I want to show an alternate image ("bandwidth thief", etc).

Here's my current, working config:

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?ourdomain\.com/.*$ [NC]
RewriteRule \.(gif|jpe?g|swf|flv|bmp|png)$ - [NC,F,L]


Now, I'm guessing that you have to alter the referrer higher up in the chain, then the default fallthrough action will force 403, but I don't know how to implement it.

hoothelp
03-10-2010, 06:36 AM
Hello.

One solution is to do it as multiple cond/rule blocks.


RewriteEngine On

# Ebay Site - stolen.png
RewriteCond %{HTTP_REFERER} ^http://([^.]+\.)?ebay\.com/.*$ [NC]
RewriteRule \.(gif|jpe?g|swf|flv|bmp|png)$ /stolen.png [L]

# General Sites - Forbidden
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?ourdomain\.com/.*$ [NC]
RewriteRule \.(gif|jpe?g|swf|flv|bmp|png)$ - [NC,F,L]


Hope this helps,
- C. Aaron Smith