Forum Moderators: phranque

Message Too Old, No Replies

.htaccess Blocking Specific eBay Item Images

         

sunshineteam

3:26 pm on Sep 13, 2008 (gmt 0)

10+ Year Member



I tried searching, but couldn't find an exact answer for this.

I have a person linking to my images on my server on eBay.

The other problem is that I use eBay as well, so I can't just block all of the eBay HTTP_REFERER traffic.

I want to block one specific auction to put up an image that I have created.

So if the referrer string has the pattern 123456789 in the URL, it will serve all images with my redirected image.

This is what I have so far:


RewriteCond %{HTTP_REFERER} ^http://(.+\.)?ebay\.com/ [NC]
RewriteCond %{HTTP_REFERER} ^123456789.*$ [NC]
RewriteRule \.(gif¦GIF¦jpg¦JPG)$ http://www.mydomain.com/images/imagetheft/170261407400.gif [L,R]

It's obviously not working.

Line one was to match traffic from ebay.
Line 2 was to match the item id pattern in the HTTP_REFERER string.
Line 3 is the image I want them to be served.

What did I do wrong?

Samizdata

4:20 pm on Sep 13, 2008 (gmt 0)

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



What did I do wrong?

I notice you have a "start anchor" ^ on the second line - remove that.

You might also dispense with the R in the last line - [L] should be enough.

Welcome to WebmasterWorld!

...

sunshineteam

4:22 pm on Sep 13, 2008 (gmt 0)

10+ Year Member



I've tried several other things. Nothing.

From all the info I've looked at, this should be working, but it's not:


RewriteCond %{HTTP_REFERER} (^.*$)123456789(^.*$) [NC]
RewriteRule \.(gif¦GIF¦jpg¦JPG)$ http://www.mydomain.com/images/imagetheft/170261407400.gif [L,R]

In the above, I only want the string "123456789" to be present in the page the image is going to be served on. If it is, line 2 serves the image of death.

sunshineteam

4:39 pm on Sep 13, 2008 (gmt 0)

10+ Year Member



Ah yes, how did I miss that [R] ?

Well, I tried this with no success:


RewriteCond %{HTTP_REFERER} ^http://(.+\.)?ebay\.com/ [NC]
RewriteCond %{HTTP_REFERER} 123456789.*$ [NC]
RewriteRule \.(gif¦GIF¦jpg¦JPG)$ http://www.mydomain.com/images/imagetheft/170261407400.gif [L]

and this, without success either:


RewriteCond %{HTTP_REFERER} (^.*$)123456789(.*$) [NC]
RewriteRule \.(gif¦GIF¦jpg¦JPG)$ http://www.mydomain.com/images/imagetheft/170261407400.gif [L]

However, in the 1st of 2 examples just mentioned here, the offending auction gets served broken image boxes, and my good auction is still working. So I know something's on the right track.

sunshineteam

4:57 pm on Sep 13, 2008 (gmt 0)

10+ Year Member



Tried this, and same results. Broken image, but not the image I want them to be served:


RewriteCond %{HTTP_REFERER} (^.*)123456789(.*$) [NC]
RewriteRule .? http://www.mydomain.com/images/imagetheft/170261407400.gif [L]

g1smd

6:41 pm on Sep 13, 2008 (gmt 0)

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



Don't include the domain name in the target URL if the .htaccess file is on the same server as the image.

Including the domain name forces a redirect, when you most likely want a rewrite.

g1smd

6:45 pm on Sep 13, 2008 (gmt 0)

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



Maybe the referrer is https?

RewriteCond %{HTTP_REFERER} ^https?://(.+\.)?ebay\.com/ [NC]
RewriteCond %{HTTP_REFERER} 123456789
RewriteRule \.(gif¦GIF¦jpe?g¦JPE?G)$ /images/imagetheft/170261407400.gif [L]

I have made a number of amendments. I'd be surprised if it didn't work now.

Make sure you flush your browser cache, before testing.

g1smd

6:48 pm on Sep 13, 2008 (gmt 0)

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



Stuff like this couldn't possibly work:

(^.*$)123456789(^.*$)
(^.*$)123456789(.*$)
(^.*)123456789(.*$)

as it has multiple starts and ends, or the ^ and/or $ is in the wrong place.

jdMorgan

7:15 pm on Sep 13, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




RewriteCond %{HTTP_REFERER} ^https?://([^.]+\.)*ebay\.com/ [NC]
RewriteCond %{HTTP_REFERER} 123456789
RewriteCond %{REQUEST_URI} !^/images/imagetheft/170261407400\.gif$
RewriteRule \.(gif¦jpe?g)$ /images/imagetheft/170261407400.gif [NC,L]

The new negative-match RewriteCond prevents an 'infinite' loop, where a previously-rewritten request for the replacement image would be rewritten to another request for the replacement image ad-infinitum, or until the browser or server gives up. Other tweaks for efficiency.

You must completely flush your browser cache before testing new code, and after any successful load of your images. For example, if you browse to one of your other auctions --one that this rule does not block-- then your browser will cache the image. If you then browse to the auction where image loading is blocked by this rule, then your browser will show you the image from its cache, and won't send a request for that image to the server. So, since no request is sent, and the image is served from your local browser cache, it will appear that the rule isn't working unless you flush out your browser cache.

Important: Change the broken pipe "¦" character in the RewriteRule pattern to a solid pipe before use; Posting on this forum modifies the pipe character.

Jim

sunshineteam

10:27 pm on Sep 13, 2008 (gmt 0)

10+ Year Member



jdMorgan, that's the one that works.

I had it working with this clumsy piece earlier today:


#RewriteCond %{HTTP_REFERER} .*170261407400.* [NC]
#RewriteRule .*\image_1\.gif$ http://www.mydomain.com/images/imagetheft/170261407400.gif [L]
#
#RewriteCond %{HTTP_REFERER} .*170261407400.* [NC]
#RewriteRule .*\image_2\.gif$ http://www.mydomain.com/images/imagetheft/170261407400.gif [L]
#
#RewriteCond %{HTTP_REFERER} .*170261407400.* [NC]
#RewriteRule .*\image_3\.gif$ http://www.mydomain.com/images/imagetheft/170261407400.gif [L]
#
#RewriteCond %{HTTP_REFERER} .*170261407400.* [NC]
#RewriteRule .*\image_4\.gif$ http://www.mydomain.com/images/imagetheft/170261407400.gif [L]

I have since switched to the 4 line code jdMorgan has listed here.

The explanations here help me understand what is happening.

Thanks so much everybody.