Forum Moderators: phranque

Message Too Old, No Replies

Allowing Google Images in .htaccess

         

teasers

1:55 pm on Sep 14, 2005 (gmt 0)

10+ Year Member



Hi,

While preventing hotlinking to my images, I want to allow only Google to access the files on the server.

The important thing is that there are several different types of entries in the log file like:

images.google.com/imgres
google.co.uk/imgres
images.google.de/imgres

So I think a rule to allow:

1. Any subdomains or www before .google.
i.e. [google.xx...]
or [images.google.xx...]

2. And any TLD after .google.
i.e. .google.co.uk/imgres
or .google.co.uk/search

will be fine.. allowing other directories like "search" will not be important, that's no problem.

I have found this:

!^http://[^/.]\.google.*$ [NC]

but I may be completely wrong, so I will be pleased to hear your comments..

Current .htaccess is something like this:

RewriteEngine on
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://www.mysite.com.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://mysite.com.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://my.ip.xx.xx.*$ [NC]
RewriteRule .*[Jj][Pp][Gg]$¦.*[Gg][Ii][Ff]$¦.*[Zz][Ii][Pp]$¦.*[Pp][Nn][Gg]$ [mysite.com...] [R,L]

teasers

2:11 pm on Sep 14, 2005 (gmt 0)

10+ Year Member



or, something like this?

!^http://([a-z0-9]+\.)?google.*$ [NC]

which also has versions like:

!^http://([a-z0-9-]+\.)?google.*$ [NC]
!^http://([-a-z0-9]+\.)?google.*$ [NC]

jdMorgan

5:04 pm on Sep 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Adding google/imgres or /search, switching to an internal 'silent' rewrite instead of an external redirect, and cleaning up, how about:

RewriteEngine on
RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mysite\.com [NC]
RewriteCond %{HTTP_REFERER} !^http://my\.ip\.123\.45 [NC]
RewriteCond %{HTTP_REFERER} !^http://.*google\.(com¦(co\.)?[a-z]{2})/(imgres¦search) [NC]
RewriteRule \.(jpg¦gif¦zip¦png)$ /myfile.jpe [NC,L]

Jim

teasers

5:15 pm on Sep 14, 2005 (gmt 0)

10+ Year Member



Well, thanks for the answer. :)

Will try this within 15 minutes..

teasers

6:03 pm on Sep 14, 2005 (gmt 0)

10+ Year Member



Hi jdMorgan,
Again, thanks for the help.

I have changed the code with yours, and no errors, it's working great.

I just don't have ability to test the:

RewriteCond %{HTTP_REFERER}!^http://.*google\.(com¦(co\.)?[a-z]{2})/(imgres¦search) [NC]

tag. I think I understood the part after .google.

Just one question: Does .* before google mean "include all subdomains"? Because, it is important to include:

images.google.com....

for example, in the expression.

thank you..