WP Discourse - Relinking Comments After Moving Blog

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 to 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!

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 my Discourse?

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.

6 Likes

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.

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 blog.domain.com also turns store.domain.com into 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!

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?

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

1 Like

I literally just did remap domain.com 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?

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

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.

1 Like