如何将nginx $ request_uri部分映射到变量
问题描述:
我在this question中发现谁将$ request_uri的第一个目录映射到nginx变量。
我需要做的是白衣2个目录和一个文件:本地主机:80/DIR1/DIR2/file.html地图为localhost:80/$ TOPDIR/$ secondir/$文件
我做的:
map $request_uri $topdir {
~(?<captured_topdir>[^\/]*[^\/]) $captured_topdir;
}
map $request_uri $secondir{
~([^\/]?<secondir>[^\/]) $secondir;
}
map $request_uri $endpart {
~([^\/]*[^\/]?<endpart>) $endpart;
}
但没有运气,当我在nginx上试用它时,只有$ topdir工作正常!
谢谢!
答
我finnaly以不同的方式解决这个问题,没有地图。刚刚在我使用的位置
if ($request_uri ~ "^(.*)/(.*)/(.*).*$") {
set $first $1;
set $second $2;
set $third $3;
}
然后现在,$第一,$第二和$第三有每个部分。