Thanks - solve an htaccess replace text issue

6 replies
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.
#$20 #htaccess #issue #replace #solve #text
  • Profile picture of the author webpro4hire
    try this:

    Code:
    RewriteRule ^images/([^Z]*)Z(.*) http://thumbs.ebaystatic.com/pict/$1\3$2 [N]
    Cheers,
    WP4H
    {{ DiscussionBoard.errors[3183068].message }}
  • Profile picture of the author KirkMcD
    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.
    {{ DiscussionBoard.errors[3183221].message }}
    • Profile picture of the author kindsvater
      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.
      {{ DiscussionBoard.errors[3183501].message }}
      • Profile picture of the author Brandon Tanner
        Originally Posted by kindsvater View Post

        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.
        <?php
        $string = '1234512345';
        $replaced = preg_replace('/3/', 'Z', $string, 1);
        ?>

        In the example above, $replaced would output '12Z4512345'
        Signature

        {{ DiscussionBoard.errors[3184179].message }}
        • Profile picture of the author kindsvater
          Thanks. One issue still out there is that if there is no text to replace the image does not load. I didn't see this issue earlier but have since using the preg_replace. But since it appears virtually every eBay image has a zero in it, I'll use replacing the first zero instead of a 3.
          {{ DiscussionBoard.errors[3184278].message }}
  • Profile picture of the author webpro4hire
    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
    {{ DiscussionBoard.errors[3184368].message }}

Trending Topics