Forum Moderators: phranque

Message Too Old, No Replies

rewriterule requires refresh?

         

Tiribulus

4:11 am on Jan 19, 2010 (gmt 0)

10+ Year Member



Hi folks,
This has really got me goin.

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,

Tiribulus

4:56 am on Jan 19, 2010 (gmt 0)

10+ Year Member



I've been twiddling wi ththe code and made some changes to this:

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.

g1smd

9:51 am on Jan 19, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



It's your caching.

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.

jdMorgan

3:29 pm on Jan 19, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The code needs a fix and some cleanup. The fix is to prevent an 'infinite' redirection loop if you protect the same filetype as you use for your 'alternate image' and to allow for FQDN-format hostnames and alternate ports. The clean-up is for efficiency:

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]

Replace all broken pipe "¦" characters above with solid pipe characters before use; Posting on this forum modifies the pipe characters. Flush your browser cache after any change to your server-side code.

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

Tiribulus

5:10 pm on Jan 19, 2010 (gmt 0)

10+ Year Member



Thanks guys.

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

jdMorgan

5:49 pm on Jan 19, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No, just leave it exactly as it was; It will accept any port, FQDN- or non-FQDN-format hostname, and URL-path, http or https, www- or non-www and any case variations in the referer. Therefore, it should work with any referer that contains your domain name, no matter what funky satellite proxy or mobile-format-conversion gateway the request may pass through.

Jim

Tiribulus

10:45 pm on Jan 19, 2010 (gmt 0)

10+ Year Member



Please give me a little while

Tiribulus

2:23 am on Jan 20, 2010 (gmt 0)

10+ Year Member



That appears to be working, Thanks. I have been super tied up with work today. I'll post a proper response as soon as I get a chance.

jdMorgan

2:38 am on Jan 21, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No worries -- Most of us only check in a few times throughout the day, so no-one should expect "IM-like" response times...

Jim