2016-08-03 27 views
0

我有Nginx的規則:檢查Nginx的拍攝變量

location ~ ^/a/(.*) { 
    return 301 /b/$1; 
} 

所以當URL是http://example.com/a/something,它返回http://example.com/b/something

如果URL是http://example.com/a/,它返回http://example.com/b/。但如果$1未定義,我需要http://example.com/a/

我不成功嘗試使用if

location ~ ^/a/(.*) { 
    if ($1) { 
    return 301 /b/$1; 
    } 
} 

回答

0

它是那麼容易:

location ~ ^/a/(.+) { 
    return 301 /b/$1; 
}