Forum Moderators: phranque
I am hoping that someone can help me out. Basically, I want to prevent sites other than major SEs from hot linking to my images.
Online communities seem to really like my maps and every time one of those pages get viewed, I get zapped with 15k - 60K of bandwidth. And they never include a link. Also, there seems to be so much of it, it has a minor effect on my stats.
I got the image protection rewrite portion of this script over on Webmaster General, but thought subsequent discussion might be better here.
I already had the HTTP_HOST rewrite in place, then added the HTTP_REFERRER.
I added the script to my .htaccess file and looked at my Google cache .. no images. So I figure it must be doing the first part of the job (preventing hot linking), but it's excluding at least 1 SE (Google).
Here is my script:
<*> - I fixed the broken pipes in this line when I pasted it into my file. I didn't see any anywhere else.
RewriteEngine on
RewriteCond %{HTTP_HOST}!^www.mysite.com [NC]
RewriteCond %{HTTP_HOST}!^$
RewriteRule ^(.*) [mysite.com...] [L,R=301]
RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER}!^http?://(www\.)?mysite\.com [NC]
RewriteCond %{HTTP_REFERER}!^http?://([^\?]+)?google\.[^/]+ [NC]
RewriteCond %{HTTP_REFERER}!^http?://([^\?]+)?yahoo\.[^/]+ [NC]
RewriteCond %{HTTP_REFERER}!^http?://([^\?]+)?msn\.[^/]+ [NC]
RewriteCond %{HTTP_REFERER}!^http?://([^\?]+)?wisenut\.[^/]+ [NC]
RewriteCond %{HTTP_REFERER}!^http?://([^\?]+)?gigablast\.[^/]+ [NC]
RewriteCond %{HTTP_REFERER}!^http?://([^\?]+)?ask\.[^/]+ [NC]
RewriteCond %{HTTP_REFERER}!^http?://([^\?]+)?aol\.[^/]+ [NC]
RewriteCond %{HTTP_REFERER}!^http?://([^\?]+)?alltheweb\.[^/]+ [NC]
RewriteCond %{HTTP_REFERER}!^http?://([^\?]+)?hotbot\.[^/]+ [NC]
RewriteCond %{HTTP_REFERER}!^http?://([^\?]+)?teoma\.[^/]+ [NC]
RewriteCond %{HTTP_REFERER}!^http?://([^\?]+)?altavista\.[^/]+ [NC]
RewriteCond %{HTTP_REFERER}!^http?://([^\?]+)?looksmart\.[^/]+ [NC]
RewriteCond %{HTTP_REFERER}!^http?://([^\?]+)?lycos\.[^/]+ [NC]
RewriteCond %{HTTP_REFERER}!^http?://([^\?]+)?netscape\.[^/]+ [NC]
<*>RewriteRule \.(jpe?g¦png¦gif)$ /myad.gif [NC,L]
Help really appreciated.
RewriteCond %{HTTP_REFERER} !^http://216\.239\.(3[2-9]¦[45][0-9]¦6[0-3])\..*www\.mysite\.com
The bit at the end including your site's domain is used to be sure that the G cache is being used to view a cache of your site, and not someone else's (who hotlinked to your site).
Change the broken pipe "¦" characters above to solid pipes before use.
Jim
yes, the space was there in the .htaccess file
I don't know what happened with the error message .. and showing all the extra '/' and '\' characters.
Maybe something weird .. I'm on a new server.
RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER} !^http?://(www\.)?mysite\.com [NC]
RewriteCond %{HTTP_REFERER} !^http?://([^/\?]+)?google\. [NC]
RewriteCond %{HTTP_REFERER} !^http?://([^/\?]+)?yahoo\. [NC]
RewriteCond %{HTTP_REFERER} !^http?://([^/\?]+)?msn\. [NC]
RewriteRule \.(jpe?g¦png¦gif)$ - [F]
Flush your browser cache before and while testing any changes to your access-control code.
Jim
With this one, the images didn't show on google.
RewriteEngine on
RewriteCond %{HTTP_HOST}!^www.mysite.com [NC]
RewriteCond %{HTTP_HOST}!^$
RewriteRule ^(.*) [mysite.com...] [L,R=301]
RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER}!^http?://(www\.)?mysite\.com [NC]
RewriteCond %{HTTP_REFERER}!^http?://([^/\?]+)?google\. [NC]
RewriteCond %{HTTP_REFERER}!^http?://([^/\?]+)?yahoo\. [NC]
RewriteCond %{HTTP_REFERER}!^http?://([^/\?]+)?msn\. [NC]
RewriteRule \.(jpe?g¦png¦gif)$ - [F]
This was showing in the URL window when the page cache was being displayed
[64.233.187.104...]
So I added the extra line and it didn't work again. Maybe I formatted the extra line wrong?
RewriteEngine on
RewriteCond %{HTTP_HOST}!^www.mysite.com [NC]
RewriteCond %{HTTP_HOST}!^$
RewriteRule ^(.*) [mysite.com...] [L,R=301]
RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER}!^http?://(www\.)?mysite\.com [NC]
RewriteCond %{HTTP_REFERER}!^http?://([^/\?]+)?google\. [NC]
RewriteCond %{HTTP_REFERER}!^http?://([^/\?]+)?64.233.187.104\. [NC]
RewriteCond %{HTTP_REFERER}!^http?://([^/\?]+)?yahoo\. [NC]
RewriteCond %{HTTP_REFERER}!^http?://([^/\?]+)?msn\. [NC]
RewriteRule \.(jpe?g¦png¦gif)$ - [F]
And I changed the broken pipes.
RewriteCond %{HTTP_REFERER} !^http?://64\.233\.187\.104 [NC]
RewriteCond %{HTTP_REFERER} !^http://216\.239\.(3[2-9]¦[45][0-9]¦6[0-3])\.
Jim
That works, Jim! I tested it on one of my other sites as well. I really *truly* do appreciate the way you hung in there with me.
"maybe time to hit the books on regular expressions? (Link in our forum charter) "
I will .. right after I move 12 websites to a new host .. probably sometime this weekend/monday. I'm sure I'll get plenty of practice doing my 301 redirects plus these image protection. This experience has made me realize I'm not *even* ready to have a dedicated server.
As for Google images, I have my doubts whether that traffic is traffic that I want.
As time permits I will look up the appropriate IPs for other SE cache servers.
Again, Jim .. thanks big time!
dave
And I'm going to learn how to do this as well!