我有两个选项(返回和重写)重定向,我不知道哪个推荐性能,搜索引擎优化等:
## Redirect from non-www to www server { server_name example.com; # Option 1 return 301 $scheme://$host$request_uri; # Option 2 rewrite ^ http://$host$request_uri? permanent; } ## Default server config server { ... listen 192.168.1.1:80 default_server; root /www; server_name www.example.com;
选项2似乎与curl一起使用,但是在浏览器调用时它不会重定向,并且返回代码是临时重定向的代码,尽管重写指令设置为permanent:
curl -I example.com HTTP/1.1 302 Moved Temporarily Server: Nginx ... Location: http://www.example.com/ ...