# WP Discourse - Relinking Comments After Moving Blog

**URL:** https://meta.discourse.org/t/wp-discourse-relinking-comments-after-moving-blog/81942
**Category:** WordPress
**Created:** [March 2, 2018, 2:03am UTC](https://meta.discourse.org/t/wp-discourse-relinking-comments-after-moving-blog/81942 "2018-03-02T02:03:45Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![yyhmsg](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/yyhmsg/32/115542_2.png) [@yyhmsg](https://meta.discourse.org/u/yyhmsg)
#### Post date: [March 2, 2018, 2:03am UTC](https://meta.discourse.org/t/wp-discourse-relinking-comments-after-moving-blog/81942/1 "2018-03-02T02:03:45Z")

</div>

I currently use discourse as our forum and comment engine for our wordpress blog. For a number of reasons I’m considering moving the blog to a subomain - from [domain.com](http://domain.com) to [blog.subdomain.com](http://blog.subdomain.com)

The wordpress part of this is straightforward and even the nginx rewrites to keep the SEO is clear.

I’m curious, however, if there is a smooth way to not break all our existing post connections - do I do a site-wide force publish once all the urls are straight on the wordpress side - or will that make all new topics and leave all the others as confusing multiple posts with the wrong links?

Do I go into each post and update post - or will that not overwrite the existing link to the blog post in the forum topic?

Do I have to get into largescale search and replace within the discourse database to do this reliably?

Any guidance would be appreciated. Thanks!

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [March 2, 2018, 2:49am UTC](https://meta.discourse.org/t/wp-discourse-relinking-comments-after-moving-blog/81942/2 "2018-03-02T02:49:54Z")

</div>

You would be able to update everything except for the `TopicEmbed.embed_url` values by republishing the posts from WordPress to Discourse after you change the WordPress domain name. If you take that approach, you’ll need to loop through the `TopicEmbeds` on your forum and update the `embed_url` for each one.

A faster, but possibly more dangerous approach would be to use the Discourse `remap` script. You can find details about using it in this topic: [Change the domain name or rename your Discourse](https://meta.discourse.org/t/change-the-domain-name-or-rename-my-discourse/16098)

Running `discourse remap domain.com blog.domain.com` will rewrite all occurrences of `domain.com` in your database. Be sure to save a backup of your database before you try it.

---

<div class="post-metadata">

### Author: ![yyhmsg](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/yyhmsg/32/115542_2.png) [@yyhmsg](https://meta.discourse.org/u/yyhmsg)
#### Post date: [March 5, 2018, 2:57am UTC](https://meta.discourse.org/t/wp-discourse-relinking-comments-after-moving-blog/81942/3 "2018-03-05T02:57:48Z")

</div>

Thank you for the reply Simon! I think I’ll try to force publish all of the wordpress posts and then do the remap - seems straightforward enough. I’ll report back with the results, just in case others plan on carrying this out in the future.

---

<div class="post-metadata">

### Author: ![yyhmsg](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/yyhmsg/32/115542_2.png) [@yyhmsg](https://meta.discourse.org/u/yyhmsg)
#### Post date: [March 23, 2018, 2:51am UTC](https://meta.discourse.org/t/wp-discourse-relinking-comments-after-moving-blog/81942/4 "2018-03-23T02:51:40Z")

</div>

I tried the remap and it mostly worked, but I have a bunch of other subdomains so it sort of messed somethings up. remap [domain.com](http://domain.com) [blog.domain.com](http://blog.domain.com) also turns [store.domain.com](http://store.domain.com) into [store.blog.domain.com](http://store.blog.domain.com)

Can I run remap again but do remap /domain.com /blog.domain.com to get it to only match the root domain? or do I have to do a fancier regex there to get that?

Thanks for the help!

---

<div class="post-metadata">

### Author: ![Mittineague](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mittineague/32/114259_2.png) [@Mittineague](https://meta.discourse.org/u/Mittineague)
#### Post date: [March 23, 2018, 3:06am UTC](https://meta.discourse.org/t/wp-discourse-relinking-comments-after-moving-blog/81942/5 "2018-03-23T03:06:08Z")

</div>

> [@yyhmsg](#):
>
> do I have to do a fancier regex there to get that?

It looks like it matched what you wanted it to match, but also matched what you wanted it to not match. So I’d say Yes, you need a better regex.

What did the one you tried look like?

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [March 23, 2018, 3:20am UTC](https://meta.discourse.org/t/wp-discourse-relinking-comments-after-moving-blog/81942/6 "2018-03-23T03:20:36Z")

</div>

> [@yyhmsg](#):
>
> Can I run remap again but do remap /domain.com /blog.domain.com to get it to only match the root domain?

Yes, that should work. You can also use a regular expression. The code for the remap function is here: [discourse/script/discourse at main · discourse/discourse · GitHub](https://github.com/discourse/discourse/blob/master/script/discourse#L15). The function’s description gives some details about using regular expressions.

---

<div class="post-metadata">

### Author: ![yyhmsg](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/yyhmsg/32/115542_2.png) [@yyhmsg](https://meta.discourse.org/u/yyhmsg)
#### Post date: [March 23, 2018, 3:25am UTC](https://meta.discourse.org/t/wp-discourse-relinking-comments-after-moving-blog/81942/7 "2018-03-23T03:25:37Z")

</div>

I literally just did remap [domain.com](http://domain.com) [blog.domain.com](http://blog.domain.com) unfortunately… so now I would need to a regex that cleans it all up.

so something that would  
remap //[anysub].blog.domain.com to //[anysub].domain.com

right?

---

<div class="post-metadata">

### Author: ![Mittineague](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mittineague/32/114259_2.png) [@Mittineague](https://meta.discourse.org/u/Mittineague)
#### Post date: [March 23, 2018, 3:46am UTC](https://meta.discourse.org/t/wp-discourse-relinking-comments-after-moving-blog/81942/8 "2018-03-23T03:46:23Z")

</div>

Hmmm, as you had the double slashes as part of the pattern I don’t see why that would have matched `store.domain.com` against `//domain.com`

---

<div class="post-metadata">

### Author: ![yyhmsg](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/yyhmsg/32/115542_2.png) [@yyhmsg](https://meta.discourse.org/u/yyhmsg)
#### Post date: [March 23, 2018, 1:32pm UTC](https://meta.discourse.org/t/wp-discourse-relinking-comments-after-moving-blog/81942/9 "2018-03-23T13:32:17Z")

</div>

Thanks I just did a few more remaps to clean up and all is well now:

remap store.blog store  
remap docs.blog docs, etc.
