2011-06-12 87 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