Get Remote Image and use Mod_rewrite

Started by ukgimp, July 26, 2011, 11:25:52 AM

Previous topic - Next topic

ukgimp

I have some datafeed sites, now a lot of folk would just link to the image and drag it off the remote server. Not me :-)

I would like to do the following, and I dont really know if it is possible but I reckon it should be.

I have a db driven site, with 1000's of item.

The image URL they have provided, could very well be like the following one (but of some product):

http://www.somesite.co.uk/images/product123.jpg

In my code instead of :

Quote<img src="http://www.google.co.uk/images/product123.jpg" alt="$product" />

I want:


Quote<img src="/images/product123.jpg" alt="$product" />

Then I think I need a script to pull the image in and display it, so some sort of modrewrite so when the following is seen:

/images/product123.jpg

it really calls

/script/getimage.php?id=123

Is what I am talking about possible, overkill I know, but I want the perception that the images are mine.

Its either than or snag every image with a script which I have done in the past.


Rooftop

We've done it so that on first call we snag the image, resize and store locally in the past - faster that way.  However your way should work.  I guess something like:

RewriteEngine On
RewriteRule ^images/([0-9.]+).jpg$ script/getimage.php?id=$1

Then some appropriate cleanup on the incoming get var

thesaintv12

I do this using a VB app.  It is not a very elegant process yet, but I save a product feed csv then the app downloads each image in the feed and renames it locally, I then upload this to the web server.

Another advantage of this is that you can rename the image to be a bit more SEO friendly.

As you can probably tell, I am from a desktop apps background.  It works, but your idea sounds nicer.


ukgimp

Nearly there, but this is weird.

I have it working on my local server

I have rewrites working on the main server, but when I add the new rewrite it wont work.

Any suggestions.

This is the rewrite directive that works locally

RewriteRule ^prodimage/([0-9a-zA-Z\/\-\.]+).jpg$ includes/getimage.php?image_id=$1

If no rewrites were working I would at least know where to look, all works locally, but one rule does not work remotely.

I can call the script locally no problem

http://mydevsite/prodimage/2/589172-200x200.jpg

Any ideas?

Cheers

Rich

ukgimp

>>Question > /dev/null

Maybe you need to ask me the stupid question as I dont know what you mean :-)

ukgimp

Not sure that is going to give me anything.

Its jus this part broken that bugs me, as I cant for the life of me think why it might not be working. Mucho frustating, this is close to be finished :-(

ukgimp

>>what is the difference between them?

a php version.

Do you know of a reason why a server might interpret a rewrite rule differntly from one server to another?

I have had o put the code back now grrr, i cant find the issue and I have to eat.

Thank for your help

Rooftop

When you say "not working" what is the actual symptom?  Are you getting any error, or is it as if the rule just isn't being translated.
If the latter, are the htaccess files identical - not just same rules, but same order? 

ukgimp

The first rules are being followed. The new one works locally but nit on live server.

It does not work, no error. Like I have the syntax or it is not recognised.

I did mess around with the order to test but no joy.

I will check it thoroughly though.

Could windows end of lines be a problem?

ukgimp

Well, I got it working, which is great. Now means that files looks like they are mine :-)

rewriteRule ^prodimage/(.*)$ includes/getimage.php?image_id=$1

Made it looser and it worked.

Anyone interested in the method I would be happy to share, for me it is a great looking way to un-affiliate-site a site.

Thanks for the help so far.

ukgimp

Keeping them the same. I suppose I could write my url on to look good.

Why, do you think the image has metadata in it that could give the game up?