Nginx Rewrite:只更改索引位置?

PGZ*_*PGZ 4 rewrite nginx

仅当用户没有URI时,如何将用户发送到新位置?我正在尝试以下,但它不起作用...它总是把我发送到/ newlocation

rewrite ^/$ http://www.domain.com/newlocation permanent;
rewrite ^/(.*)$ http://www.domain.com/$1 permanent;
Run Code Online (Sandbox Code Playgroud)

基本上,我需要的是:

如果用户在浏览器www.domain.org上写入,则会发送到www.domain.com/newlocation如果用户在浏览器www.domain.org/something上写入,则会发送到www.domain.com/something

谢谢!

kol*_*ack 10

我不确定为什么你现在的方法不起作用.^/$应该只匹配/.也许它是当前配置的其他东西.这是一台应该做你想做的服务器.

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;
  }
}
Run Code Online (Sandbox Code Playgroud)

  • 我需要一些时间来确定第一个表达式中还有一个"=" (2认同)