Nginx is probably my favorite web server up to this moment, and it runs and serves websites on all of my servers. I should say, I also like Apache web server too, but not as much as Nginx.

Today, I need to redirect from one url path to another. It took me a while to get it right, and I’d better write it down before it’s forgotten.

This is what I want: https://demo.example.com/login -> https//demo.example.com/demo/login.

Here is one solution that is working well for me:

...
location = /login {
  return 301 /demo/login;
}
...

Of course, the above 3 lines need to be included in the Nginx’s configuration file.

Reference: