Forum Moderators: phranque

Message Too Old, No Replies

redirecting outbound links? help

help using mod_rewrite to redirect the src of an img tag

         

shadowaspect

12:40 pm on Nov 24, 2008 (gmt 0)

10+ Year Member



Hi all.

I need a bit of help. I have a blog that I have recently moved from Typepad to a self hosted wordpress install, however There were a lot of <img> tags in the various posts whose src attribute was pointing to typepad's servers.

I am wondering if I can use mod_rewrite to rewrite the urls when the image is requested so that they are coming from a different server (one that I control, where a copy of the images is stored) to save me replacing all the img tags in 3 years of blog posts manually?

thanks in advance

Matt

phranque

12:46 pm on Nov 24, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld [webmasterworld.com], Matt!

you must do that rewrite from the typepad server since that is where the request is going.

shadowaspect

12:58 pm on Nov 24, 2008 (gmt 0)

10+ Year Member



thanks for the welcome.

I thought that might be the case, unfortunately I can't as our account was closed so I don't have access to the servers anymore. I was hoping I could intercept and rewrite the outbound links.

Are there any other ways that I might be able to acheive this? I'm thinking of some kind of JS action?

cheers

phranque

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

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



i'm sure you can do something in js that will rewrite those image tags in a body onload action.
you might as well write a script that updates all the entries containing image tags in the database.
otherwise you will have problems with non-js-enabled browsers.

Samizdata

1:31 am on Nov 25, 2008 (gmt 0)

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



If I understand the question correctly (never a certainty) you have a database, probably MySQL, full of posts contaning links to uploaded images that look something like this:

img src="http://www.example.com/images/whatever.jpg"

You could export the relevant database table as a text file (SQL, including "Drop Table If Exists") then use a decent text editor to do a "find and replace" on "example.com/images", change it to wherever the images now reside (e.g. "example2.com/images"), then re-import the database table.

Apologies if I misunderstood you.

...