question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Images are not working after migration.

See original GitHub issue

I’m trying to migrate a blog from mydomain.com to mydomain.com/blog but the images paths are broken, they point to /content/images instead of /blog/content/images even if I add subdir option in config.js -> paths. Also the usage of absolute=“true” when posting the image does not change anything.

I’ve tracked the cause of this and here is where I’m at:

core/config/url.js/181
if (context === 'image' && data.image) {
    // here absolute is true

    urlPath = data.image;
    imagePathRe = new RegExp('^' + ghostConfig.paths.subdir + '/' + ghostConfig.paths.imagesRelPath);
    absolute = imagePathRe.test(data.image) ? absolute : false;

    // but after the RegEx it will be false as in DB the path of the images does not contain
    // subdir because the blog was previously on the root of the domain

    secure = data.image.secure;
    if (absolute) {
        urlPath = urlPath.replace(new RegExp('^' + ghostConfig.paths.subdir), '');
        baseUrl = getBaseUrl(secure).replace(/\/$/, '');
        urlPath = baseUrl + urlPath;
    }

    return urlPath;
}

Also if I comment out the last line return urlPath; the script will go next to return createUrl(urlPath, absolute, secure); and this will return the correct urls for my images.

I’d appreciate any help on this. Thank you.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
ErisDScommented, Dec 10, 2015

@deiucanta That won’t work because you’ll get double subdirectories for all future uploads and any other items where the subdirectory is accounted for.

This is a one-time migration issue, you need to fix your bad data, as @cobbspur described, and then everything will work fine.

2reactions
ErisDScommented, Dec 9, 2015

When you upload an image, Ghost writes a relative path for your image to the database image or markdown fields. You have changed what the correct relative path is, any links you created would also be broken in the same way. Ghost does not know that you have changed this and it does not doctor the text content of posts in any way.

Going through and fixing this is a necessary part of migrating between a subdirectory and non-subdirectory install. There may be some tools out there to help cc @cobbspur, but this is expected behaviour and not a bug.

Read more comments on GitHub >

github_iconTop Results From Across the Web

WordPress images not showing after migration - ARZ Host
The most typical cause of missing photos following a WordPress conversion is that the website's Home and site URL settings are incorrect. WordPress...
Read more >
WordPress Images Not Showing Up After Migration: Fix it now
1. Upload the broken, or not existed image files ... When you migrate a blog, it happens that a brief connection issue can...
Read more >
After migration images no longer load in WordPress
Your WordPress website has been migrated; Your images are not loading, but everything else is loading normally; If you look in your browser...
Read more >
How to Fix Image Links after WordPress Migration
Right click on one of the missing images and get the image information from the menu there. This will include the URL where...
Read more >
Images are not shown on frontend after migration - LitExtension
After data migration, you probably see all images are not shown on frontend but still visible in the backend (admin dashboard).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found