Frage

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?

War es hilfreich?

Lösung

try this

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

Andere Tipps

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

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top