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

**URL:** https://meta.discourse.org/t/how-do-i-change-the-legacy-cdn-urls-of-images-in-posts/97518
**Category:** Support
**Created:** [September 19, 2018, 4:09am UTC](https://meta.discourse.org/t/how-do-i-change-the-legacy-cdn-urls-of-images-in-posts/97518 "2018-09-19T04:09:39Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![snakeninny](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/snakeninny/32/115522_2.png) [@snakeninny](https://meta.discourse.org/u/snakeninny)
#### Post date: [September 19, 2018, 4:09am UTC](https://meta.discourse.org/t/how-do-i-change-the-legacy-cdn-urls-of-images-in-posts/97518/1 "2018-09-19T04:09:39Z")

</div>

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 `http://7xibfi.com1.z0.glb.clouddn.com/`, and suggested me to change the URLs to my custom one `http://cdn.iosre.com/` ASAP.

The problem is that most of the old posts on my [website](http://iosre.com), e.g. this [one](http://iosre.com/t/hopper-mac/1428), 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 [http://7xibfi.com1.z0.glb.clouddn.com/uploads/default/original/1X/735abc46bddabe584790cf2218d5d9bbc1f2501a.png](http://7xibfi.com1.z0.glb.clouddn.com/uploads/default/original/1X/735abc46bddabe584790cf2218d5d9bbc1f2501a.png) becomes [http://cdn.iosre.com/uploads/default/original/1X/735abc46bddabe584790cf2218d5d9bbc1f2501a.png](http://cdn.iosre.com/uploads/default/original/1X/735abc46bddabe584790cf2218d5d9bbc1f2501a.png), 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?

Thanks,

Yinglu

---

<div class="post-metadata">

### Author: ![itsbhanusharma](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/itsbhanusharma/32/180717_2.png) [@itsbhanusharma](https://meta.discourse.org/u/itsbhanusharma)
#### Post date: [September 19, 2018, 6:11am UTC](https://meta.discourse.org/t/how-do-i-change-the-legacy-cdn-urls-of-images-in-posts/97518/2 "2018-09-19T06:11:08Z")

</div>

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:

> [@Replace a string in all posts](https://meta.discourse.org/t/replace-a-string-in-all-posts/48729):
>
> bookmark This guide explains how to replace a string in all posts within a Discourse instance. person_raising_hand Required user level: System Administrator warning Console Access Required Want to replace a string in all the posts on a site? Let’s get started! warning WARNING: We strongly recommend you take a full backup before proceeding, and make sure your string replacement is specific enough to affect only the places you want it to. If this string replacement goes wrong, every…

---

<div class="post-metadata">

### Author: ![snakeninny](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/snakeninny/32/115522_2.png) [@snakeninny](https://meta.discourse.org/u/snakeninny)
#### Post date: [September 19, 2018, 8:28am UTC](https://meta.discourse.org/t/how-do-i-change-the-legacy-cdn-urls-of-images-in-posts/97518/3 "2018-09-19T08:28:22Z")

</div>

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!

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [September 19, 2018, 12:49pm UTC](https://meta.discourse.org/t/how-do-i-change-the-legacy-cdn-urls-of-images-in-posts/97518/4 "2018-09-19T12:49:52Z")

</div>

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

---

<div class="post-metadata">

### Author: ![snakeninny](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/snakeninny/32/115522_2.png) [@snakeninny](https://meta.discourse.org/u/snakeninny)
#### Post date: [September 19, 2018, 1:28pm UTC](https://meta.discourse.org/t/how-do-i-change-the-legacy-cdn-urls-of-images-in-posts/97518/5 "2018-09-19T13:28:56Z")

</div>

@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 `http://7xibfi.com1.z0.glb.clouddn.com/uploads/default/213/acc63bd2c2d03f28.png`.

And I have tried to `grep -r 7xibfi.com1.z0.glb.clouddn.com /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?

---

<div class="post-metadata">

### Author: ![itsbhanusharma](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/itsbhanusharma/32/180717_2.png) [@itsbhanusharma](https://meta.discourse.org/u/itsbhanusharma)
#### Post date: [September 19, 2018, 1:47pm UTC](https://meta.discourse.org/t/how-do-i-change-the-legacy-cdn-urls-of-images-in-posts/97518/6 "2018-09-19T13:47:11Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![snakeninny](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/snakeninny/32/115522_2.png) [@snakeninny](https://meta.discourse.org/u/snakeninny)
#### Post date: [September 19, 2018, 2:53pm UTC](https://meta.discourse.org/t/how-do-i-change-the-legacy-cdn-urls-of-images-in-posts/97518/7 "2018-09-19T14:53:04Z")

</div>

> [@itsbhanusharma](#):
>
> s3 cdn url

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

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [September 19, 2018, 3:13pm UTC](https://meta.discourse.org/t/how-do-i-change-the-legacy-cdn-urls-of-images-in-posts/97518/8 "2018-09-19T15:13:50Z")

</div>

Did you rebuild after you changed the value? ([Enable a CDN for your Discourse](https://meta.discourse.org/t/enable-a-cdn-for-your-discourse/14857), which is linked to in the `yml` file you edited says to rebuild after the change.)

> [@itsbhanusharma](#):
>
> If You only have to replace links in database, there is a rake find & replace task there just for this purpose.

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 - #2 by zogstrip](https://meta.discourse.org/t/disable-cdn-causes-old-images-with-cdn-url-can-not-be-shown/29657/2) for two ways to do it. The simpler way is:

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

```

---

<div class="post-metadata">

### Author: ![snakeninny](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/snakeninny/32/115522_2.png) [@snakeninny](https://meta.discourse.org/u/snakeninny)
#### Post date: [September 20, 2018, 2:44am UTC](https://meta.discourse.org/t/how-do-i-change-the-legacy-cdn-urls-of-images-in-posts/97518/9 "2018-09-20T02:44:51Z")

</div>

EDIT: after a whole night, `http://iosre.com/uploads/default/original/1X/735abc46bddabe584790cf2218d5d9bbc1f2501a.png` becomes `http://cdn.iosre.com/uploads/default/original/1X/735abc46bddabe584790cf2218d5d9bbc1f2501a.png`, 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 `http://7xibfi.com1.z0.glb.clouddn.com/uploads/default/original/1X/735abc46bddabe584790cf2218d5d9bbc1f2501a.png` become `http://iosre.com/uploads/default/original/1X/735abc46bddabe584790cf2218d5d9bbc1f2501a.png`, which is hosted right on the server instead of on the CDN.

What can I do to use new CDN host `cdn.iosre.com` for all legacy URLs?

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [March 5, 2019, 8:00am UTC](https://meta.discourse.org/t/how-do-i-change-the-legacy-cdn-urls-of-images-in-posts/97518/10 "2019-03-05T08:00:43Z")

</div>

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