Forum Moderators: phranque

Message Too Old, No Replies

Need RewriteCond to allow self hosted pix ONLY from ebay

         

angiemci

12:02 pm on May 28, 2007 (gmt 0)

10+ Year Member



Hi, I'm not good with htaccess, so bear with me please.

I have working code to allow my friendly domains access to my images. Unfriendly links serve up an alternate image.

I want to allow links self hosted pictures on ebay, but serve up an alt graphic to other auctions that aren't mine.

I have found that my auctions all contain "9753" in the item #. (no quotes, and I have randomly picked 9753, my numbers are different).

I have 2 sample links from ebay that I would like to work:

http: //cgi.ebay.com/ws/eBayISAPI.dll?ViewItem&ih=004&sspagename=STRK%3AMESE%3AIT&viewitem=&item=975321971110&rd=1&rd=1

http: //cgi.ebay.com/Ebay_Auction_Title_W0QQitemZ975321971110QQihZ004QQcategoryZ2747QQssPageNameZWDVWQQrdZ1QQcmdZViewItem

I am completely stumped with how to match on
- ebay.com/ws/ AND 9753 in the 1st example
- ebay.com/ AND 9753 in the 2nd example

I am thinking that if I can get this to work, that all other auctions will not be able to load my images. I do realize that the 9753 could change in the future, and I that I may have to edit this # at some point.

Can anyone help me?
Thanks!

g1smd

12:08 pm on May 28, 2007 (gmt 0)

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



Two RewriteCond lines:

One checks the referrer domains.
The other checks for the "9753".
If both pass then no redirect occurs.

However, isn't the 9753 just the serial number of the auction and all the other auctions at the moment also begin with that?

angiemci

12:20 pm on May 28, 2007 (gmt 0)

10+ Year Member



Hi,

Can you please give me an example? I'm a braindead newbie at this point!

Yes, many auctions can begin with 9753....but the auctions I have found offending do not begin with these #'s. While this is not a fullproof fix, I do think it is a start.

I really do appreciate your help!
Thanks!

angiemci

1:26 pm on May 28, 2007 (gmt 0)

10+ Year Member



Here's what I have now and doesn't work (with respect to the ebay auctions):

RewriteEngine on
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://(www\.)?mydomain\.com/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://(www\.)?anotherdomain\.com/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://(cgi\).?ebay\.com/.*$ [NC]
RewriteCond %{HTTP_REFERER}!(.+/)?9753.*$ [NC]
RewriteRule .*\.(jpe?g¦gif¦bmp¦png)$ - [F]

And to expand on the item #, I believe this varies based on ebay region, tool used to post, and other many factors. Many auctions begin with lots of other #s, not just the sample # I provided.

Hoping someone can tell me where I have gone awry :)

g1smd

1:39 pm on May 28, 2007 (gmt 0)

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



>> RewriteCond %{HTTP_REFERER} !^http://(cgi\).?ebay\.com/.*$ [NC]

should be something like this:

RewriteCond %{HTTP_REFERER} !^http://(cgi\.)?ebay\.com/.*$ [NC]

angiemci

1:49 pm on May 28, 2007 (gmt 0)

10+ Year Member



Oh my gosh...I do believe it works!

I was so busy focusing on the line containing the item # check, that I overlooked what you found so quickly!

Thank you so much for your help!

g1smd

2:04 pm on May 28, 2007 (gmt 0)

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



I have spent many hours missing simple mistakes like that in my own code; but always spot them in other people's code in seconds...

angiemci

2:29 pm on May 28, 2007 (gmt 0)

10+ Year Member



It is working now, with one little glitch....
I use image xyz.jpg in my auction. Displays fine for my auctions.

However, if someone visits my auction (& the image is cached), when the offending auction is visited, image xyz.jpg displays (as requested by the auction) instead of freebookwithpurchase.jpg, which is the replacement image for offending auctions.

Doing a Ctrl Refresh serves up freebookwithpurchase.jpg .

RewriteRule \.(gif¦jpg)$ [mydomain.com...] [R,L]

How do I expire the images so that the offending auction receives the correct image?

Thanks!

angiemci

2:41 pm on May 28, 2007 (gmt 0)

10+ Year Member



This code seems to have solved the problem...

ExpiresActive on
ExpiresDefault "access plus 0 seconds"
ExpiresByType image/gif "access plus 0 seconds"
ExpiresByType image/jpg "access plus 0 seconds"

Is this the best way to accomplish what I am hoping for? Or do you see anything that should be elimintated/combined?

Thanks!

jdMorgan

3:44 pm on May 28, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That 'expires' code is self-defeating, in that now every request for your images will come to your server instead of being served from browser and network caches. I suggest you simply don't worry about the cached images, since they will be a non-issue except for repeat visitors. And those repeat visitors *have already cached your image* and won't be affected by your new expires headers until their caches expire on their own.

If you do wish to set your expires headers, set them to something reasonable like a day or a week, in order to reduce your server load. As it is, your server could crash if your item gets mentioned in slashdot or becomes suddenly popular.

The code posted above has a latent fault, in that it no longer allows *any* referer that does not contain your auction number. It doesn't seem to meet your desired goal of serving an alternate image. It also shows evidence of being auto-generated, and can be implemented much more efficiently and correctly like this:


RewriteEngine on
RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain\.com [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?anotherdomain\.com [NC]
RewriteCond %{HTTP_REFERER} !^http://(cgi\.)?ebay\.com/.+item.9753[0-9]+ [NC]
RewriteCond %{REQUEST_URI} !^/free-book-with-purchase\.gif
RewriteRule \.(jpe?g¦gif¦bmp¦png)$ http://mydomain.com/images/free-book-with-purchase.gif [R=302,L]

Note that the last RewriteCond prevents an 'infinite' loop when the 'free-book-with-purchase.gif' file itself is requested as a result of the redirect.

Replace the broken pipe "¦" characters above with solid pipe characters before use; Posting on this forum modifies the pipe characters.

Jim

[edited by: jdMorgan at 3:45 pm (utc) on May 28, 2007]

angiemci

4:40 pm on May 28, 2007 (gmt 0)

10+ Year Member



Point taken. Cache time is now set to 1 week. (You can tell I'm not a full-time webmaster)

Yes, the majority of the code was taken from some postings and tweaked. And I just was not able to implement the code for the 2 conditions for the ebay auctions, so that I could successfully host images for my auctions, but hopefully not everyone else's too. (Ebay doesn't close all offending auctions as they advertise that they do.)

As far as my alt image...it is intended to get the attention of the seller(s). More than likely, they are not aware that their ads no longer show the intended item, but that their ad now states there is a free gift with the purchase. Perhaps they'll get the point when the winners inquire about the "free gift" :)

I am very appreciative of all you experts that chipped in to help me implement the solution at hand.