之前给nginx做301重定向的时候经常会这样写:
server {
listen 80;
server_name www.jb51.net jb51.net;
if ($http_host = www.jb51.net) {
rewrite (.*) http://jb51.net$1;
}
...
}
实际标准的写法应该是
server {
listen 80;
server_name www.jb51.net;
return 301 http://jb51.net$request_uri;
}
server {
listen 80;
server_name jb51.net;
...
}