Nginx重写:仅更改索引位置?

| 仅当用户没有URI时,如何才能将用户发送到新位置?我正在尝试以下操作,但是它不起作用...它总是将我发送到/ newlocation
rewrite ^/$ http://www.domain.com/newlocation permanent;
rewrite ^/(.*)$ http://www.domain.com/$1 permanent;
所以基本上,我需要的是: 如果用户在浏览器www.domain.org上书写,它将发送到www.domain.com/newlocation 如果用户在浏览器www.domain.org/something上书写,它将发送到www.domain.com/something 谢谢!     
已邀请:
        我不确定您当前的方法为何行不通。 ^ / $应该只匹配/。也许它是当前配置的其他东西。这是应该执行您想要的操作的服务器。
server {
  server_name www.domain.org;

  # Only match requests for /
  location = / {
    rewrite ^ http://www.domain.com/newlocation permanent;
  }

  # Match everything else
  location / {
    rewrite ^ http://www.domain.com$request_uri? permanent;
  }
}
    

要回复问题请先登录注册