Changing a relative link in Drupal via SQL

May 10, 2010 - by Ian Hasell

Sometimes you may need to change all the relative links in Drupal. For example I had a test site inside another Apache website. When the site was ready to go live created a new Apache site but all the links in Drupal nodes referenced theold path.

/testsite/file.ext should be /file.ext.

To fix this I ran some SQL agaisnt the database to update the node_revisions table.

update node_revisions set body = replace(body,'/testsite/','/');
update node_revisions set teaser = replace(teaser,'/testsite/','/');
Before doing this you should backup your table just in case anything goes wrong. You would also need to be careful to make sure that path you are replacing is nor repeated in the path anywhere else i.e.


If this was the case you would adapt the above SQL tor change the name of your theme in this instance.