Reputation: 129
I want to deny hotlinks for some files from other sites , but allow it to sub-domains of the same domain
I have written this code which is work great , but the problem is that it block my other sub-domains
RewriteCond %{HTTP_REFERER} !^$
RewriteCond expr "! %{HTTP_REFERER} -strmatch '*://%{HTTP_HOST}/*'" [NC]
RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ - [F,NC]
the problem is when a visitor visit www.myDomain.com and requests an image in sub.myDomain.com the hotlink is disallowed
please note thea the domain name is a variable (so I have to use something like %{HTTP_HOST})
Upvotes: 2
Views: 542
Reputation: 18671
You can use:
RewriteCond %{HTTP_HOST} ^(?:[^.]+\.)?([^.]+\.[^.]+)$
RewriteCond %1::%{HTTP_REFERER} !^(.*?)::(?:$|.*\1) [NC]
RewriteRule \.(jpg|jpeg|gif|png|bmp)$ - [F,NC,L]
Upvotes: 2