Fix Drupal Content Images after moving your Drupal site

When you upload an image to the content of a Drupal 7 site. Drupal 7 adds the full path of the image to the actual content. If you are using Drupal 7 check the following table:
field_data_body
inspect the body_value column and you will notice that full relative path of the image within the body of the Drupal content.

That goes without saying that any images/assets added to the content will be broken, if you move your site from one directory to another or from a subdirectory to the root of the site.

Here is the mysql fix:
Run the following query to replace the path within the body_value column:

Example 1

Moving from subdirectory “/drupal7_test/” to “/”

update field_data_body set body_value=REPLACE(body_value, '/drupal7_test', '') where 1=1;

Example 2

Moving from subdirectory “/drupal7_test/” to “/drupal7_live/”

update field_data_body set body_value=REPLACE(body_value, '/drupal7_test', '/drupal7_live') where 1=1;
Let's share thisShare on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn