使用apache重定向规则是这样写的,把它翻译成nginx
像这样:RewriteCond %{HTTP_HOST} example.org RewriteRule (.*) http://www.example.org$1
server { listen 80; server_name www.example.org example.org; if ($http_host = example.org) { rewrite (.*) http://www.example.org$1; } ... }
上面的方式是错误的,应该是下面的这种方式:
server { listen 80; server_name example.org; return 301 http://www.example.org$request_uri; } server { listen 80; server_name www.example.org; ... }
On versions prior to 0.9.1, redirects can be made with:rewrite ^ http://www.example.org$request_uri?;