google images hotlink redirect with htaccess

638 views Asked by At

I want to redirect google image searches (hotlinked images) directly to my page. My current solution works, but for all referers. I want to make it only for google image search, but I dont know how. Currently I have this (simplified) htaccess code:

RewriteCond %{HTTP_USER_AGENT} !Googlebot-Image [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?mydomain.com [NC]
RewriteCond %{REQUEST_FILENAME} .*jpg$ [NC]
RewriteRule (.*) /hotlink.php?p=$1 [L]

This solution works, but I want to make it only for google. I tried

 RewriteCond %{HTTP_REFERER} ^http(s)?://(www\.)?google.com [NC]
 RewriteCond %{REQUEST_FILENAME} .*jpg$ [NC]
 RewriteRule (.*) /hotlink.php?p=$1 [L]

but does not work.

1

There are 1 answers

0
Kristian Vitozev On

What about this one?

RewriteCond %{HTTP_REFERER} ^http(s)?://(.*\.)?google\..* [NC]