Forum Moderators: phranque
Problem is when i look at the Google results of my site and i click on Cache , doesn't load the right images and is loading the image set to appear when hotlink is enabled.
RewriteCond %{REQUEST_URI} !^/images/allowed-folder/
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !google. [NC]
RewriteCond %{HTTP_REFERER} !search?q=cache [NC]
RewriteCond %{HTTP_REFERER} !msn. [NC]
RewriteCond %{HTTP_REFERER} !yahoo. [NC]
RewriteRule .*\.(jpg¦png)$ http://www.example.com/foldername/hotlinkimage.jpe [R,NC]
I think line with search?q=cache is the problem.
Thank you
[edited by: jdMorgan at 8:27 pm (utc) on July 15, 2009]
[edit reason] example.com [/edit]
Unescaped periods in regular-expressions patterns mean "match any single character." So, your patterns are not likely matching exactly what you expect.
Your patterns will also match if the "search company" name is in any part of the referrer, including a query string. Again, that will result in unexpected matches. You do better with more-specific patterns such as
"^([^./]+\.)*google\.co"
and
"^([^./]+\.)*msn\.co"
etc.
Because of the parenthesized subpattern starting each pattern, any and all subdomains of the specified domain will be matched.
Note that the negative match on "/" characters in that subpattern means that these patterns will only match the referring domain, and not the URL-path, anchor/fragment, or query string.
Assuming I'm a hotlinker, this prevents me from hotlinking your images by simply adding a fake fragment or query string to my referring page's URL, like
www.my-site.com/my-page.html?bypass-rowtc2's-anti-hotlink-code-by-including-the-word-google-here
or just
www.my-site.com/?google.
A pattern of "\.(jpg¦png)$" would be entirely equivalent to the pattern in your rule, but faster.
When testing access-control code like this, be sure to completely flush (delete) your browser cache between tests. Otherwise your browser will not send a request to your server, but instead simply show you the locally-cached object.
Jim