nginxhttp-redirecthttp-status-code-301

Redirecting from subfolder to new subdomain


I am trying to write a redirect / for the following

Current setup:

New Set up

What I need to do is redirect:

https://website/forum/demoforum to https://forum.newwebsite/demoforum

Everything from the last needs to be replicated on the direct / rewrite.

I have tried the following but they dont work:

location /forum/ {
    return 301 https://forum.newwebsite.org;
}

location /forum/ {
    return 301 https://forum.newwebsite.org$request_uri;
} 

Solution

  • please try this:

    location /forum/ {
        rewrite ^/forum/(.*)$ https://forum.newwebsite.org/$1 permanent;
    }