How to fix preview links in chats retaining old urls for pic preview after migrating mm to new domain?


After moving mattermost to a new domain name and new server (basically moving docker containers and updating the base url) link previews from before the migration still refers to the old url.

Eg, the HTML for a link preview in the previous instance would look like this:

<img class="attachment__image attachment__image--opengraph large_image" aria-label="miniature de fichier" tabindex="0" src="https://mattermost.olddomain.tld/api/v4/image?">

But in the new instance there’s en empty SVG tag instead:

<svg xmlns="" viewBox="0 0 1120 630" style="max-height: 630px; max-width: 1120px; vertical-align: middle;"></svg>

If I play around with the previous URL and replace the domain, like this:

<img class="attachment__image attachment__image--opengraph large_image" aria-label="miniature de fichier" tabindex="0" src="https://subdomain.newdomain.tld/mattermost/api/v4/image?">

Then the image is fetched and displayed.

I also have some recursive paths going on sometimes:


Which leads to:

error fetching remote image: Get https://subdomain.newdomain.tld/mattermost/api/v4/image? Get https://subdomain.newdomain.tld/mattermost/api/v4/image? address forbidden, you may need to set AllowedUntrustedInternalConnections to allow an integration access to your internal network

Any ideas how I could restore link and picture preview in links posted before the migration ?

It also seems half of the link I post don’t generate a preview anymore but that might not be related. Looks like something is timing out ; also, even though both the old server and the new are running the same versions and databases and files the preview link layout is smaller in the new server.

It also doesn’t fetch/display the same OG info.

Thanks :).

I’m not 100% certain about this, so please make a backup of your database first just in case, but I’ve had a look through the Mattermost Server code, and I think the data stored in the LinkMetadata table is a cache of the various metadata that is related to some (or all) of the issues you are seeing here. If it is deleted, it should be recreated with the correct URL on the next request for the effected posts. So, my suggestion is, on your database, do a DELETE from LinkMetadata; and clear that table out, and then see if the problem is resolved.

As I said at the beginning though, make sure to take a backup of your database just in case this has other side-effects I haven’t spotted!

1 Like

Thanks a lot for digging out. Sorry for the late reply, I was afk for a week.

I’ll be trying out your suggestion in the coming days and will let you know how it went.