Globally rewrite broken image links in node bodies I'm migrating my site from Drupal 6 to Drupal 7, and while most of it just worked after migration, the change from the Image module to the core image handling left a large number of broken images on the site.

Images that were inserted in the node body were not handled at all by the migration, and the links are now in an invalid format. Fortunately, fixing those links is pretty straightforward, I just need to change

http://mysite.com/sites/default/files/images/[image-name].[style].jpg


to 

http://mysite.com/sites/default/files/styles/[style]/public/images/[image-name].jpg


This looks like it should be relatively straightforward to do, but I didn't find an easy way to do this replacement. I found the Search and Replace Scanner module, but that doesn't seem to allow using parts of the original match in the substitution. 

How can I fix these image links all at once without having to do it manually?
Assuming MySQL, you can fix that up with a search and replace SQL query.

Perhaps easiest from the MySQL command line, though could also use db_query.

The pattern is:

UPDATE tablename SET fieldname = REPLACE(fieldname, 'search', 'replace');


Something like:

UPDATE field_data_body SET body_value = REPLACE(body_value, 'sites/default/files/images/', 'sites/default/files/styles/[style]/public/images/');

UPDATE field_revision_body SET body_value = REPLACE(body_value, 'sites/default/files/images/', 'sites/default/files/styles/[style]/public/images/');


Backup the database first.

You may need to do it one image style at a time, or else make all the images uses a new standard style.

More info: http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_replace