WP Discourse - Relinking Comments After Moving Blog


(Yyhmsg) #1

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!


(Simon Cossar) #2

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.


(Yyhmsg) #3

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.


(Yyhmsg) #4

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!


(Mittineague) #5

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?


(Simon Cossar) #6

Yes, that should work. You can also use a regular expression. The code for the remap function is here: discourse/discourse at master · discourse/discourse · GitHub. The function’s description gives some details about using regular expressions.


(Yyhmsg) #7

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?


(Mittineague) #8

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


(Yyhmsg) #9

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.