Two domains, conditional redirect

Dear Discourse experts!

We have been running a discourse forum (DOMAIN1) for 3 years. Now we want expand the discussion scope and add DOMAIN2. We succeeded getting them both active with letsencrypt thanks to this post. We will keep both domains active which worked after step 1 on this post. The second is redirected to the main domain name, which is good.

Part of the transition is to move all existing categories to a new top level category.

DOMAIN2 will become the main discourse domain, DOMAIN1 will remain linked so external links to posts still work.

Here is the question: How can we add a redirect if a “vanilla” DOMAIN1 is called (just the root URL, no path) to the new top level category URL? All other DOMAIN1 calls (with paths) should keep the existing path (no change, already works). Doing this will minimize confusion since everyone going to the DOMAIN1 will land in the category and everything will look similar as before.

Hope someone has a suggestions how add this conditional redirect with our double domain setup.

Thank you!
Merten

1 Like

You’re going to have a hard time: A single Discourse instance cannot live at multiple URLs; and permalink redirection does not function for existing routes such as topic view.

4 Likes

So you’re saying there isn’t a simple way to do the following?

(1) go to domain1.com and it’s running discourse (with main hostname domain1.com - works)
(2) go to domain2.com and it goes to domain1.com/c/example/18 (what we also want)
(3) go to domain2.com/t/topic/1 and it shows either domain1.com/t/topic/1 or domain2.com/t/topic/1 (current works)

we are transitioning and want only the root of domain2.com to redirect to a category. is there any sort of URL rewriting that can do this?

1 Like

If domain2 is only serving redirection rules, then yes you can write an nginx config to do that; the details of which are out of scope for Meta.

2 Likes

Could not the site map plugin serve as the raw data for the nginx 302 redirects?

1 Like

We got it working by adding the following to the web.ssl.template.yml file:

if ($host = domain2.com) {
    rewrite ^/$ /c/example/18 permanent;
}
2 Likes

Please move that to a replace directive in your app.yml instead, or future upgrades are going to be a pain for you!

3 Likes

Ok thanks for that!!!

1 Like