答えを変更して、再帰的に機能させるようにします。
最初に最初からバージョン番号をスローし、これを最初のディレクトリに追加します
location ~ "^/([0-9]{1}\.[0-9]{1})/([a-zA-Z0-9]+)/(.*\.doc)$" {
rewrite .* /$2@$1/$3;
}
だから今URL:
/1.2/junior/many_sub_dir_here/test.doc -> /junior@1.2/many_sub_dir_here/test.doc
これlocation
で、ディレクティブ belove が再帰的な場所として機能します (再帰的な場所の呼び出しを許可するように nginx をマークします):
location ~ "^(/[a-zA-Z0-9]+@)([0-9]{1}\.[0-9]{1})/(([a-zA-Z0-9]+@[0-9]{1}\.[0-9]{1}/)*)([a-zA-Z0-9]+)/(.*\.doc)$" {
rewrite .* /$1$2/$3$5@$2/$6;
}
あなたのURLの場合、次のように機能します
/junior@1.2/x1/x2/x3/test.doc --> /junior@1.2/x1@1.2/x2/x3/test.doc
$1 = /junior@
$2 = 1.2
$3 =
$4 =
$5 = x1
$6 = x2/x3/test.doc
/junior@1.2/x1@1.2/x2/x3/test.doc --> /junior@1.2/x1@1.2/x2@1.2/x3/test.doc
$1 = /junior
$2 = 1.2
$3 = x1@1.2/
$4 = x1@1.2/
$5 = x2
$6 = x3/text.doc
/junior@1.2/x1@1.2/x2@1.2/x3/test.doc --> /junior@1.2/x1@1.2/x2@1.2/x3@1.2/test.doc
$1 = /junior@
$2 = 1.2
$3 = x1@1.2/x2@1.2/
$4 = x2@1.2/
$5 = x3
$6 = test.doc
この最後の URL は上記のブロックの正規表現と一致しなくなるlocation
ため、ここでは次のような最終的なロケーション ブロックを使用します。
location ~ ".*(@[0-9]{1}\.[0-9]{1})/[^@/]+\.doc$" {
root root /usr/home/fs;
try_files $uri =404;
}