# Links broken after move

**URL:** https://meta.discourse.org/t/links-broken-after-move/135913
**Category:** Self-hosting
**Created:** [December 14, 2019, 1:33am UTC](https://meta.discourse.org/t/links-broken-after-move/135913 "2019-12-14T01:33:12Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![Mark\_Schmucker](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mark_schmucker/32/124810_2.png) [@Mark\_Schmucker](https://meta.discourse.org/u/Mark_Schmucker)
#### Post date: [December 14, 2019, 1:33am UTC](https://meta.discourse.org/t/links-broken-after-move/135913/1 "2019-12-14T01:33:13Z")

</div>

Many of our intra-forum links are broken after moving to a new server. I had created the new server at a temporary url [staging.example.com](http://staging.example.com) to help with the transition, but now that the transition is complete, many links at [forum.example.com](http://forum.example.com) still point to [staging.example.com](http://staging.example.com) (which no longer exists).

I have verified the app.yml and rebuilt:

> containers/app.yml: DISCOURSE\_HOSTNAME: [forum.example.com](http://forum.example.com)

I have searched admin \> settings for any vestiges of “staging”.

DNS has long since propagated.

I see this old [reference](https://github.com/discourse/wp-discourse/issues/52), not sure if that’s related.

If no fix is possible except manual editing, any hints how to find all occurrences? The search button doesn’t work well for this.

---

<div class="post-metadata">

### Author: ![Remah](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/remah/32/70590_2.png) [@Remah](https://meta.discourse.org/u/Remah)
#### Post date: [December 14, 2019, 1:37am UTC](https://meta.discourse.org/t/links-broken-after-move/135913/2 "2019-12-14T01:37:51Z")

</div>

> [@Change the domain name or rename your Discourse](https://meta.discourse.org/t/change-the-domain-name-or-rename-my-discourse/16098):
>
> bookmark This guide explains how-to change the domain name of your Discourse site, and includes information about setting up DNS changes, editing configuration files, updating site settings, and correcting social logins and post content to reflect your new domain name. warning This guide is for self-hosted Discourse instances that were installed using our [installation guide on GitHub](https://github.com/discourse/discourse/blob/main/docs/INSTALL-cloud.md). If you are [hosted by Discourse](https://www.discourse.org/pricing), please see [Configure your domain name for hosted Discourse](https://meta.discourse.org/t/configure-your-domain-name-for-hosted-discourse/21827) for specific …

---

<div class="post-metadata">

### Author: ![Mark\_Schmucker](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mark_schmucker/32/124810_2.png) [@Mark\_Schmucker](https://meta.discourse.org/u/Mark_Schmucker)
#### Post date: [December 14, 2019, 1:39am UTC](https://meta.discourse.org/t/links-broken-after-move/135913/3 "2019-12-14T01:39:25Z")

</div>

I did that. All worked great except now I have broken links.

---

<div class="post-metadata">

### Author: ![Remah](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/remah/32/70590_2.png) [@Remah](https://meta.discourse.org/u/Remah)
#### Post date: [December 14, 2019, 1:52am UTC](https://meta.discourse.org/t/links-broken-after-move/135913/4 "2019-12-14T01:52:20Z")

</div>

So you’re saying the remap and/or rebake failed?

> [@Change the domain name or rename your Discourse](https://meta.discourse.org/t/change-the-domain-name-or-rename-your-discourse/16098/1):
>
> ### Replace all instances of the old name with the new name in posts
> 
> All the existing posts will still refer to the old domain. Let’s fix that:
> 
> ```plaintext
> ./launcher enter app
> discourse remap talk.foo.com talk.bar.com
> rake posts:rebake
> 
> ```
> 
> This remaps text in posts from the old URL to the new URL, then regenerates all posts just in case.

---

<div class="post-metadata">

### Author: ![Mark\_Schmucker](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mark_schmucker/32/124810_2.png) [@Mark\_Schmucker](https://meta.discourse.org/u/Mark_Schmucker)
#### Post date: [December 14, 2019, 1:57am UTC](https://meta.discourse.org/t/links-broken-after-move/135913/5 "2019-12-14T01:57:38Z")

</div>

Sorry, I did not do a remap. I’ll try that tonight.

---

<div class="post-metadata">

### Author: ![Mark\_Schmucker](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mark_schmucker/32/124810_2.png) [@Mark\_Schmucker](https://meta.discourse.org/u/Mark_Schmucker)
#### Post date: [December 14, 2019, 7:50am UTC](https://meta.discourse.org/t/links-broken-after-move/135913/6 "2019-12-14T07:50:22Z")

</div>

> [@Remah](#):
>
> So you’re saying the remap and/or rebake failed?

Yes, now I can say the remap failed.

```plaintext
> /var/www/discourse# discourse remap staging.example.com forum.example.com
> Rewriting all occurences of staging.example.com to forum.example.com
> THIS TASK WILL REWRITE DATA, ARE YOU SURE (type YES)
> YES
> Error: ERROR: duplicate key value violates unique constraint "unique_post_links"
> DETAIL: Key (topic_id, post_id, url)=(8718, 57455, https://forum.example.com/t/exampletopic/4606/336) already exists.
> The remap has only been partially applied due to the error above. Please re-run the script again.

```

I re-ran it as instructed and got the same error, on the same (topic\_id, post\_id, url) key.

I can get to the rails console and run some SQL/ActiveRecord if you can tell me what to run. Or [Data Explorer](https://meta.discourse.org/t/32566?silent=true).

---

<div class="post-metadata">

### Author: ![Remah](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/remah/32/70590_2.png) [@Remah](https://meta.discourse.org/u/Remah)
#### Post date: [December 14, 2019, 7:57am UTC](https://meta.discourse.org/t/links-broken-after-move/135913/7 "2019-12-14T07:57:15Z")

</div>

Someone else will have to help you with this because I’m not sure why you would have duplicate key value.

---

<div class="post-metadata">

### Author: ![Mark\_Schmucker](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mark_schmucker/32/124810_2.png) [@Mark\_Schmucker](https://meta.discourse.org/u/Mark_Schmucker)
#### Post date: [December 14, 2019, 8:25am UTC](https://meta.discourse.org/t/links-broken-after-move/135913/8 "2019-12-14T08:25:33Z")

</div>

Ironically, the offending topic 8718 and post 57455 is in a PM between two users lamenting that the links are broken!

But using [data explorer](https://meta.discourse.org/t/32566?silent=true), I see only one post with id 57455. I don’t know why remap is complaining.

---

<div class="post-metadata">

### Author: ![michaeld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/michaeld/32/1594_2.png) [@michaeld](https://meta.discourse.org/u/michaeld)
#### Post date: [December 14, 2019, 10:28am UTC](https://meta.discourse.org/t/links-broken-after-move/135913/9 "2019-12-14T10:28:29Z")

</div>

The post probably contains both the old and new URL already. Just edit it and remove them.

---

<div class="post-metadata">

### Author: ![Mark\_Schmucker](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mark_schmucker/32/124810_2.png) [@Mark\_Schmucker](https://meta.discourse.org/u/Mark_Schmucker)
#### Post date: [December 15, 2019, 1:08am UTC](https://meta.discourse.org/t/links-broken-after-move/135913/10 "2019-12-15T01:08:56Z")

</div>

I cleaned up a few posts and was able to complete the remap. However the rebake ran to 30% then encountered errors and hung the system and I had to reboot. System has adequate memory and disk space.

Question: After reboot, in ‘top’, there is a ruby process using 60% CPU. Is that the rake job? Would it resume after reboot?

---

<div class="post-metadata">

### Author: ![michaeld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/michaeld/32/1594_2.png) [@michaeld](https://meta.discourse.org/u/michaeld)
#### Post date: [December 15, 2019, 6:38am UTC](https://meta.discourse.org/t/links-broken-after-move/135913/11 "2019-12-15T06:38:45Z")

</div>

It’s probably Sidekiq busy on rebakes. Go to /sidekiq on your forum to check.
