Forum Moderators: phranque

Message Too Old, No Replies

code for search engines & hotlink protection

search engine, hot linking code

         

testy

1:30 pm on Aug 28, 2006 (gmt 0)

10+ Year Member



Just now I noticed that I am getting vistors for my images from google but not from yahoo/msn

I have changed the code to allow yahoo and msn referrers

RewriteEngine on
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://mysite.com/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://mysite.com$ [NC]
RewriteCond %{HTTP_REFERER}!^http://(www\.)?search.yahoo.com/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://(www\.)?search.yahoo.com$ [NC]
RewriteCond %{HTTP_REFERER}!^http://(www\.)?yahoo.com/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://(www\.)?yahoo.com$ [NC]
RewriteCond %{HTTP_REFERER}!^http://(www\.)?search.google.com/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://(www\.)?search.google.com$ [NC]
RewriteCond %{HTTP_REFERER}!^http://(www\.)?images.search.yahoo.com/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://(www\.)?images.search.yahoo.com$ [NC]
RewriteCond %{HTTP_REFERER}!^http://(www\.)?msn.com/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://(www\.)?msn.com$ [NC]
RewriteCond %{HTTP_REFERER}!^http://(www\.)?search.msn.com/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://(www\.)?search.msn.com$ [NC]
RewriteRule .*\.(jpg¦jpeg¦gif¦png¦bmp¦js.*)$ - [F,NC]

Is every thing ok with this code.

What is the http referer for live.com (if any)

Caterham

1:52 pm on Aug 28, 2006 (gmt 0)

10+ Year Member



I (personally) would just use

RewriteEngine on
# using the lex. eq. operator instead of a regEx
RewriteCond %{HTTP_REFERER} !=""
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mysite\.com [NC]
RewriteCond %{HTTP_REFERER} !(google¦msn¦yahoo)\.com [NC]
RewriteRule \.(jpe?g¦gif¦png¦bmp¦js.*)$ - [F,NC]

BTW: What, if someone uses e.g. google.co.uk? So may be

!(google¦msn¦yahoo)\. [NC]

would be another way to catch this.

testy

2:09 pm on Aug 28, 2006 (gmt 0)

10+ Year Member



thanks caterham

will the code
!(google¦msn¦yahoo)\.com
capture referers like search.msn.com

also is that \ in \.com necessary

testy

2:17 pm on Aug 28, 2006 (gmt 0)

10+ Year Member



will some thing like this be better

RewriteCond %{HTTP_REFERER}!(google¦msn¦yahoo).* [NC]

testy

3:09 pm on Aug 28, 2006 (gmt 0)

10+ Year Member



caterham's code works perfectly

I have tested it within my sites by creating subdomain and using it in domains with extension other than .com

The final code I used is

RewriteCond %{HTTP_REFERER}!(google¦yahoo¦msn)\. [NC]