How do I change the legacy CDN URLs of images in posts?

Hi Discourse team,

Forgive me if there’re duplicate topics but I don’t even know what keywords to search, so I started a new topic describing my problem.

Recently I got update from my CDN provider that they will abandon the legacy URLs like, and suggested me to change the URLs to my custom one ASAP.

The problem is that most of the old posts on my website, e.g. this one, contains images with the legacy URLs, and they will be not accessible after the CDN provider abandon them.

So I guess, what I need to do, is to replace all the hosts in legacy URLs in the database with the new host, so becomes, which keeps the same image accessible for always.

Is there a simple and rookie-friendly way to replace all the legacy URLs with the new one?



It should (at very least) begin with changing the Discourse CDN URL in your yml file and then rebuilding discourse.

If You only have to replace links in database, there is a rake find & replace task there just for this purpose.
Documentation here:


I have already changed the CDN URL in app.yml and rebuilt discourse, but the legacy URLs will not be affected, right?
Seems the link is what I’m looking for; I will try it once the backup is done. Thanks for the info!


Search here for “rebake” (I think that the yml for might include the command).

@itsbhanusharma @pfaffman Thanks for helping!

I have tried rake and 44 posts were remapped. But I see another situation in my post, the source of the post looks like <img src="/uploads/default/213/acc63bd2c2d03f28.png" width="496" height="138"> but for readers who don’t have access to the post source and if they copy the image address, it turns out to be

And I have tried to grep -r /var/discourse, turns out this URL appears in databases such as /var/discourse/shared/standalone/postgres_data/base/16400/361518 and css files such as /var/discourse/shared/standalone/uploads/stylesheet-cache/mobile_51397cef7eb3aa4cc8e1939c4ef7156c29bfc9e2.css, and rake doesn’t work on these files.

Any other ideas how can I change all legacy CDN URLs?

I smell something fishy here!

Can you confirm in your admin area if the s3 cdn url is blank or has any value set ?

@zogstrip some time ago there was some issue surrounding the upload urls which had brought me into a very similar situation! I remember you fixed it but can this be related to that?

Sorry, what do you mean by “s3 cdn url”?

Did you rebuild after you changed the value? (Enable a CDN for your Discourse, which is linked to in the yml file you edited says to rebuild after the change.)

No, what needs to be done is to do a rebake of the posts to fix the references to the old CDN. See Disable CDN causes old images with CDN URL can not be shown for two ways to do it. The simpler way is:

# ssh into server
cd /var/discourse
./launcher enter app
rake posts:rebake

EDIT: after a whole night, becomes, so I guess it takes a while processing all URLs? I am checking more posts to double confirm.

I did rebuild after changing DISCOURSE_CDN_URL in app.yml.

I tried running rake posts:rebake, now all images with legacy URLs such as become, which is hosted right on the server instead of on the CDN.

What can I do to use new CDN host for all legacy URLs?

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