301 Permanent
Useful for handling www.yourdomain.com vs. yourdomain.com or redirecting http to https. In this case we will redirect www.yourdomain.com to yourdomain.com.
server {
listen 80;
server_name www.yourdomain.com;
return 301 http://yourdomain.com$request_uri;
}
302 Temporary
server {
listen 80;
server_name yourdomain.com;
return 302 http://otherdomain.com;
}
Redirect on specific URL
Can be permanent (301) or temporary (302).
server {
listen 80;
server_name yourdomain.com;
location /redirect-url {
return 301 http://otherdomain.com;
}
}