1

So I want to disable Hotlinking in general but allow it for the subdomain "thumbs". My .htaccess is as the following:

#HOTLINKING
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://domain.com/.* [NC]
RewriteCond %{HTTP_HOST} !^thumbs.domain.com [NC]
RewriteCond %{REQUEST_FILENAME} !hotlink.png$
RewriteRule .*\.(png)$ http://domain.com/hotlink.png [R=302,L]

However, it does not work! How can I fix this?

Jonas Kaufmann
  • 1,797
  • 3
  • 22
  • 43

1 Answers1

1

You are mixing HTTP_REFERER and HTTP_HOST. You should only use HTTP_REFERER. So:

RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://domain\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^http://thumbs\.domain\.com/ [NC]
RewriteCond %{REQUEST_FILENAME} !hotlink\.png$
RewriteRule .*\.(png)$ http://domain.com/hotlink.png [R=302,L]

or even shorter matching all subdomains (and domains ending in 'domain.com' but that's very unlikely)

RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !domain\.com/ [NC]
RewriteCond %{REQUEST_FILENAME} !hotlink\.png$
RewriteRule .*\.(png)$ http://domain.com/hotlink.png [R=302,L]
Gerben
  • 16,747
  • 6
  • 37
  • 56