2011-06-12 81 views
4

只有当用户没有URI时,我如何才能将用户发送到新位置?我想后续,但它不工作...它总是送我去/ newlocationNginx重写:只更改索引位置?

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

谢谢!

+0

这对我有用 – isuldor 2014-12-16 19:21:14

回答

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; 
    } 
} 
+1

我需要一些时间才能确定第一个表达式中还有一个“=” – bluearrow 2016-07-05 13:11:46