Forum Moderators: phranque

Message Too Old, No Replies

Using apache mod rewrite on image locations

         

JS_Harris

10:23 pm on Nov 24, 2008 (gmt 0)

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



I'm having difficulty figuring out what to place in my .htaccess file to accomplish the following. No links are involved, I'd just like to re-write the image locations.

sample image location I'd like changed:
[image.example-one.com...]

what i'd like it changed to:
[example-two.com...]

I basicaly need the domain name changed and the uid number used as the unique location. I added /s/ as a folder to keep it simple and to avoid duplicate problems with my regular images folder.

If anyone can help me with this I'd appreciate it.

g1smd

11:00 pm on Nov 24, 2008 (gmt 0)

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



First off you have to change the links on the page to point to the new URLs, as it is links that define URLs.

Next you need a rewrite to connect those URL requests to the real location on the server where that content resides.

There's plenty of example code in posts listed in the linked thread at the top of the page.

Post your best effort code here as a basis for discussion.

JS_Harris

11:32 pm on Nov 24, 2008 (gmt 0)

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



My best effort code so far would be...

RewriteEngine On
RewriteBase /
RewriteRule ^images/s/(.*)$ [image.example-one.com...] [R,L]

but I don't want to make it live without confirmation.

Actually if I could just change the base uri part of the image location from example-one to example-two that would work too.

I'm not overly worried about links, the images don't link to anything. They are affiliate images that constantly update. The reason I want to rewrite where it looks like the image is located is because of the spread of firefox image block for this particular affiliate. I'd prefer visitors block my site directly if they so choose, i'm getting emails saying my site looks funny without images when there are many of them.

phranque

4:49 am on Nov 25, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



no matter what you have on the original page that is served, when your external redirect gets returned to the browser, it will fail on the subsequent get request.
in other words it will simply take longer for your site to look funny.

g1smd

8:44 pm on Nov 25, 2008 (gmt 0)

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



Your example code has [R] which generates a 302 redirect.

However, you need both a rewrite and a redirect here and your single line of code seems to be a mashup of both things, but doesn't have any provision for parameters.

JS_Harris

1:51 am on Nov 26, 2008 (gmt 0)

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



I wanted to keep things simple for the purposes of this thread, I can usually solve issues if pointed in the right direction when I'm stumped, but the issue i'm facing is a little more complex.

If it helps, I'm pulling in affiliate offers from two sources via API/XML and have code in place to parse and handle everything. The line of code above works well with one of the two affiliates, the images are hosted with the affiliate but appear to be hosted on my site, but the second affiliate images wants none of it.

The site doesn't look silly but the rewrite fails. The images look like they are hosted over at the affiliate site still and visitors with firefox block enabled see white space when they don't want to.

I suppose I'd need to show the entire code to crack this problem but I'll go the route of hiring someone I think. I was hoping I'd missed something obvious.

edit: the images change daily, I can't simply host them myself as they're outdated immediately.

[edited by: JS_Harris at 1:53 am (utc) on Nov. 26, 2008]