I am looking for a way to do 301 redirection from one page to another.

site.com/page-1 should redirect to site.com without affecting other pages and directories.

I'm new to Nginx, please let me know which is the configuration file that I need to modify? What is the syntax to do the above redirect?

有帮助吗?

解决方案

try this

location /page-1 {
   rewrite ^/page-1$ http://$server_name permanent;
 }

其他提示

I usually prefer using return over rewrite when redirecting

location /page-1 {
  return 301 $scheme://$http_host;
}

You need to add this in the virtual host file you created before, you'll probably find it inside /etc/nginx/sites-enabled or /etc/nginx/conf.d or /etc/nginx/nginx.conf

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top