I want to redirect from www.mydomain.com to domain.com in nginx. I search the internet and found two ways:
First way
server {
listen 80;
server_name www.domain.com;
rewrite ^/(.*) http://domain.com/$1 permanent;
}
Second way
server {
listen 80;
server_name www.domain.com;
return 301 $scheme://domain.com$request_uri;
}
Both ways work. But Which one should i use and why?