Rebuild image links after moving from subdomain to subdirectory

We are moving our Ghost set up from a subdomain to a subdirectory. This seemed pretty easy as just updating the config.production.json for the new URL of the blog.

However the existing images in the articles are now broken.

How can I programmatically update the /content/images/ path to its correct location in the stories?

Is there a way to rebuild or migrate the articles/stories so that we can do it with the ghost cli? We have a couple 100s of these to work through for example.


Did not find any documentation, for this but this is how we got this to work:

  1. Edit the config.production.json file to update the new URL of your blog

  2. Make a dump of the DB and replace the paths. For example, from this SO answer.

    Dump the database to a text file

    mysqldump -u root -p[root_password] [database_name] > dumpfilename.sql

    Restore the database after you have made changes to it.

    mysql -u root -p[root_password] [database_name] < dumpfilename.sql

  3. Next restart the instance.

Alternate solution (did not try, but may work):

  1. Export the data as a json in the admin ui > Labs.
  2. Edit for changes.
  3. Reset your instance.
  4. Import the json.
1 Like

For that sort of things, I’d recommend to rewrite your urls using ngix (unless your website hasn’t gone live yet).

Yes, while that could work for some scenarios. The existing images failed to load due to internal relative linking.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.