try this
location /page-1 {
rewrite ^/page-1$ http://$server_name permanent;
}
質問
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