문제

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