
假設我收到一個 GET 請求檔/dir/01/23/file.ext
。我想提供/dir/01/23
無副檔名的檔案。檔案名稱應該是03,並且應該使用file.ext
mime 。.ext
我如何在 nginx 中編寫規則來做到這一點?
答案1
rewrite ^/dir/01/23/file.ext$ /dir/01/23 break;
或者
rewrite ^(.*)/file.ext$ $1 break;
您可能還需要指定專用位置。例如:
location /dir {
root $docroot;
}