Thanks - solve an htaccess replace text issue

by 6 replies
8
I have a script that creates a nice 'SEO'd' looking link to an eBay image (eg: mysite.com/images/123435.jpg) and using htaccess shows the real image at thumbs.ebaystatic.com/pict/123435.jpg

This is the htaccess rewrite code:

RewriteRule ^images/(.*)$ http://thumbs.ebaystatic.com/pict/$1 [R,L]

No big deal.

Except my web page still shows 123435.jpg which can readily be identified as an eBay image.

What I am doing is changing my SEO link to be: images/12Z4Z5.jpg

(easy enough to do a string replace in php to change every "3" to a "Z" - I am changing every occurrence of "3" in the image name wherever it appears)

This is where I need your help.

How do I add to or change my htaccess rewrite code to change every "Z" back to a "3" wherever it may be in a link so that the correct eBay image is retrieved?

Example: how do I do this in htaccess:

/images/12Z4Z5.jpg retrieves thumbs.ebaystatic.com/pict/123435.jpg
/images/1Z7982.jpg retrieves thumbs.ebaystatic.com/pict/137982.jpg
etc.

$20 payment made via PayPal to first person who can solve this, with me verifying it works on my website.
#programming #$20 #htaccess #issue #replace #solve #text
  • try this:

    Code:
    RewriteRule ^images/([^Z]*)Z(.*) http://thumbs.ebaystatic.com/pict/$1\3$2 [N]
    Cheers,
    WP4H
  • Since you don't know how many "Z"s there will be, you won't be able to do it directly in the .htaccess file. Well you could, but you would have to code it for every possibility for the qty of "Z"s the file name may have.

    What you could do, is pass it to a script on your site which then redirects to the image.
    I just wrote something like that, but it was for local images. I can now put any keyword as the filename and always pull up the same image because of the way I parse the url.
    • [1] reply
    • WP4H:

      For some reason only one "Q" is being replaced. I believe the [N] at the end is supposed to be recursive, but it isn't so this fails if there is more than one Q.

      Let me see if I can figure how to do a php string replace of only the 1st instance of a "3" to try and get this to work.


      Kirk:

      eBay images are apparently 12 digits long. That seems to be a fixed number.
      • [1] reply
  • Hi kindsvater,

    Sorry to hear the rewriteRule did not work as planned. I set it up on my server and it did the job, but then I don't have the same setup or know the full problem set.

    No need to send me $$$, I only accept when the solution is complete! Consider it free help, hopefully it got you closer to your goal

    Cheers,
    WP4H

Next Topics on Trending Feed