Forum Moderators: phranque
I need to prevent hotlinking but allow most of image search engines. My code:
#anti-hotlinking
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example\.com\.ar(/)?.*$ [NC]
RewriteCond %{HTTP_REFERER} !(google¦msn¦yahoo¦picsearch¦altavista¦ditto¦ask¦live¦aol)\.com(/)?.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://images\.google\. [NC]
RewriteCond %{HTTP_REFERER} !^http://.*\.search\.yahoo\.com [NC]
RewriteCond %{HTTP_REFERER} !search\?q=cache [NC]
RewriteRule .*\.(gif¦jpg¦jpeg¦bmp¦png)$ - [F,NC]
Line 3 is to allow my own site
Line 4 wants to let all those image search engines hotlink (some of these starts like this: "something.yahoo.... does the ! symbol means "contains"?
Line 5 and 6 are just in case ;) I don't want to loose yahoo and google if my code in line 4 doens't work hahah
Line 7, allow cached images.
I also have a custom 403 error (403.shtml) is there any downside in using a custom instead default?
Help appreciated!
The absence of both a start- and end-anchor, "^" and "$", in a regular-expressions pattern means that you only care if the string contains text matching the pattern, and not what position the match occurs in.
Cleaning up redundant lines characters and sub-patterns:
#anti-hotlinking
RewriteEngine on
RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example\.com\.ar/? [NC]
RewriteCond %{HTTP_REFERER} !(google妃sn尖ahoo如icsearch地ltavista圬itto地sk奸ive地ol)\.com/? [NC]
RewriteCond %{HTTP_REFERER} !search\?q=cache [NC]
RewriteRule \.(gif夸pe?g在mp如ng)$ - [F,NC]
Thanks,
Jim
If domain name is: my-domain
It should be escaped? ie: my\-\domain
And what about sites like yahoo.co.uk or yahoo.es?
If I understand correctly this line:!(google妃sn尖ahoo如icsearch地ltavista圬itto地sk奸ive地ol)\.com/
will take care of
yahoo.com
yahoo.com.something
but no yahoo.co.uk
Am I right? Should I just change the ending part?
RewriteCond %{HTTP_REFERER} !(google妃sn尖ahoo如icsearch地ltavista圬itto地sk奸ive地ol)\.[NC]