Need Help with Redirection after changing the domain of my Discourse Forum

After moving my Discourse forum to a new instance and URL, I need help with setting up domain redirection.

I want links from the old domain to redirect to the new domain. For example, a link like https://olddomain.com/t/topic/89520 should redirect to https://newdomain.com/t/topic/89520.

I’ve heard about using a 301 redirect, but I’m struggling to locate the Nginx configuration directory on my server. Any alternative solutions or guidance would be greatly appreciated.

1 Like

Hi @Anirudh_Dutta_Gupta :wave: welcome to Meta :slight_smile:

Have you seen this topic yet:

Thank you @Lilly. I’d like to know if permalinks can handle a full domain change too. Just to clarify, we’re moving from abc.domain1.com to xyz.domain2.com. Both the subdomain and the domain are changing. I’ve been reading through this discussion and wanted to confirm:

Are you trying to redirect an existing Discourse topic to an external URL? That’s not what permalinks are designed to do. I’m pretty sure that you can’t redirect anything under /t.
If you want people who visit https://hoidap.cheng.vn/t/cach-cua-do-nu-bao-binh-don-gian/70 2 to be redirected to https://cunghoangdao.info then I think your best bet is to edit the post and tell people to click the link to go to the other site.

1 Like

So you set up

3 Likes

Thank you @RGJ. How do I go about with the generic redirect? Both the current and the previous forums are on Discourse.

1 Like

Assuming you’re going to remove the current forum, it’s just a normal Apache or nginx redirect.

For nginx

server {
    server_name original.example.com;
    location / {
        rewrite ^/(.*)$ https://new.example.com/$1 permanent;
    }
}

or Apache

RewriteEngine On
RewriteRule ^(.*)$ https://new.example.com/$1 [R=301,L]

I had missed the part where you’re only moving Discourse and not migrating. Since you’re only moving domains, you don’t need the permalink redirects.

2 Likes

That’s what I was originally thinking, but I cannot find the nginx folder anywhere in the /etc directory. Am I looking in the wrong place?

That’s because there is currently a Discourse install there, which has the nginx in the container.

It would be easiest to point the old hostname to the new instance and handle the redirection there see URL rewrite for domain change in permalinks - #7 by modius

Alternatively, remove the Discourse install and set up nginx on the old instance

1 Like

Thank you @RGJ for the guidance. I just ended up doing a domain level direct from our domain name provider, and that worked. The old links are redirecting to the new links correctly.

4 Likes

Here is the method I use for a full redirection after a domain change, I mixed a few solutions offered in this forum.

in the app.yml, at the end I add the after_web_config and after_ssl blocks :

hooks:
  after_code:
    - exec:
        cd: $home/plugins
        cmd:
          - git clone https://github.com/discourse/docker_manager.git

  after_web_config:
    - replace:
        filename: /etc/nginx/nginx.conf
        from: /sendfile.+on;/
        to: |
          server_names_hash_bucket_size 64;
          sendfile on;
    - file:
        path: /etc/nginx/conf.d/discourse_redirect_1.conf
        contents: |
          server {
            listen 80;
            listen 443 ssl;
            server_name old-domain.com;
            return 301 $scheme://new-domain.com$request_uri;
          }
  after_ssl:
    - replace:
        filename: "/etc/runit/1.d/letsencrypt"
        from: /--keylength/
        to: "-d old-domain.com --keylength"

## Any custom commands to run after building
run:
  - exec: echo "Beginning of custom commands"
  ## If you want to set the 'From' email address for your first registration, uncomment and change:
  ## After getting the first signup email, re-comment the line. It only needs to run once.
  #- exec: rails r "SiteSetting.notification_email='info@unconfigured.discourse.org'"
  - exec: echo "End of custom commands"

It will redirect the old links to the new forums, without a SSL issue.

3 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.