Single page 301 redirect in Nginx

Optimal single 301 redirect:

location = /old-page {
  return 301 /new-page;
}

Try to avoid this technique that is used frequently and less optimal:

if ( $request_filename ~ old-page/ ) {
     rewrite ^ https://code.support/new-page/? permanent;
}

Simply put it in the bottom of the serverblock that’s in use inside your server configuration file. Default: /etc/nginx/sites-enabled/default .

To open the file from a terminal:

sudo nano /etc/nginx/sites-enabled/default

Add your comment