Forum Moderators: phranque
I caught somebody leeching images off my site, linking directly to them and I managed to get some code together for .htaccess that stops that. I also managed to have it redirect to another local image.
Here's the issue. If I go to the link where he is posting my images I see my original image until I refresh and then I get the first in a row of several (repeating) that he has linked from my site as the "no leeching" image and if I refresh again all the instances of my image are replaced with the "no leeching" image. This happens on several machines and several browsers on each. Every time I go back there it behaves as described, starting over with all being my original. Also, If I remove the alternate image bit, I then get my images repeated at first and they disappear upon refresh.
Conversely, inside my network at least, which is all I've been able to test to this point, on my website, my "no leeching" image displays instead of the actual image until refresh at which time it does displays the actual image.
I'm wondering if this may have something to do with the fact that all my testing has been inside my network where all these different machines access the resources on the server with the same local IP address or is it something else? My Coyote Linux gateway does DNS caching, but that's it.
I have searched until my eyeballs are falling out and I cannot find any other instance of this happening to anybody else. I don't care about this if it's only happening to us on my lan. Here is the code in .htaccess in my docroot.
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mysite.com:8080/.*$ [NC]
RewriteRule .*\.(jpe?g¦gif¦bmp¦png¦jpg)$ /srv/www/htdocs/pix/gp.jpe [L]
RewriteRule ^link([^/]*).html$ rewrite.php?link=$1 [L]
Any elucidation on this, at least to me, mind bending state of affairs would be perfectly splendid.
Thanks,
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mysite.com:8080/.*$ [NC]
RewriteRule .*\.(jpe?g¦gif¦bmp¦png¦jpg)$ [mysite.com:8080...] [R,NC,L]
I still does it, but I'm beginning to lean more to the notion that it's related to my caching on this end. If I open both sites in different tabs whichever image was loaded last on one shows up on the other until I refresh. I think them being the same URL's is confusing the browsers. I think.
Your browser will show the image previously downloaded.
That means that should someone see the 'no leeching' image and then visit your site, they'll continue to see it.
It also means if you first look at your own site, then look at the other site you'll continue to see the real image.
A cookie based solution is usually much more robust that one based on referrers as they can be missing or faked.
RewriteCond %{REQUEST_URI} !^/pix/gp\.jpe$
RewriteCond %{HTTP_REFERER} !^(https?://(www\.)?example\.com\.?(:[0-9]+)?/?.*)?$ [NC]
RewriteRule \.(jpe?g¦gif¦bmp¦png¦jpe)$ http://example.com:8080/pix/gp.jpe [NC,R=302,L]
Make sure that your replacement image is 'polite' and mentions your URL; Remember that it will be seen by the visitors to the hotlinking site, and not just the Webmaster or forum/blog/wiki poster who was responsible for the hotlinking.
Jim
I assume my forwarded port goes after the .com on the first line where the url occurs as in:
RewriteCond %{REQUEST_URI} !^/pix/gp\.jpe$
RewriteCond %{HTTP_REFERER} !^(https?://(www\.)?mysite\.com:8080\.?(:[0-9]+)?/?.*)?$ [NC]
RewriteRule \.(jpe?g¦gif¦bmp¦png¦jpe)$ [mysite:8080...] [NC,R=302,L]
Of course with the pipe characters fixed.
I don't how you keep track of all this Jim.
Thanks again
Jim