Prevent hotlinking
Added by Geoff about 15 years ago
Hi guys. I followed this cyberciti tutorial to prevent hotlinking of multimedia files, but it seems to prevent hotlinking from http://mydomain.com (no www).
Here's what I have in each virtual host:
$HTTP["referer"] !~ "^($|http://.*\.(mydomain\.*|google\.*|yahoo\.*|msn\.*|msnscache\.com/.*))" { $HTTP["useragent"] !~ "msnbot-media" { $HTTP["useragent"] !~ "Mediapartners-Google" { $HTTP["useragent"] !~ "Yahoo-MMCrawler" { $HTTP["useragent"] !~ "FeedBurner" { $HTTP["referer"] !~ "^($|http://.*/.*(q=cache.*|p=cache.*))" { url.access-deny = ( ".jpg", ".jpeg", ".png", ".gif", ".wmv", ".mpg", ".mpeg" ) } } } } } }
Does this look right? What do I need to change to allow http://mydomain.com and not just the www version? Also, are the useragent exemptions really necessary? Will search engines not be able to spider my images if I leave them out?
Thanks for any help!
Regards,
Geoff
Replies (1)
RE: Prevent hotlinking - Added by Geoff about 15 years ago
Ok I think I got it:
$HTTP["referer"] !~ "^($|.*(mydomain\.com|google\.com|yahoo\.com|msn\.com|msnscache\.com))" { url.access-deny = ( ".jpg", ".jpeg", ".png", ".gif", ".wmv", ".mpg", ".mpeg" ) } }
I trimmed it down a bit, since I'm pretty sure Google spiders pass blank referrers (which I think the above allows?). No sense in making exceptions that aren't needed. Not sure how much of what I left is needed - I'll have to do more research on that.
If anyone sees a better/simpler way to write the above code, let me know. It's working okay so far.