我想做的是:
domain.com/account/manage/somekey/ -> domain.com/account/manage/?key=somekey
domain.com/account/manage/somekey/settings/ -> domain.com/account/manage/settings/?key=somekey
somekey是一个字符串,包含A-F,a-f,长度为0-9 24个字符。
这是我对第一个的看法,但我不知道如何做第二个。
location /account/manage/ {
rewrite "^/account/manage/([A-Fa-f0-9]{24})/(.*)$" /account/manage/?key=$1;
}
答案 0 :(得分:0)
我对nginx没有多少经验,但试试这个版本:
location /account/manage/$ {
rewrite ^/account/manage/([A-Fa-f0-9]+)(/[^/]*)?/?$ /account/manage$2/?key=$1;
try_files $uri $uri/;
}
答案 1 :(得分:0)
location /account/manage/ {
rewrite "^/account/manage/([A-Fa-f0-9]{24})/(settings/)?" /account/manage/$2?key=$1;
}