Вопрос

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