Reputation: 55
i found in this question who to map the first directory of $request_uri into a nginx variable.
I need to do it whit 2 directories and one file: localhost:80/dir1/dir2/file.html map to localhost:80/$topdir/$secondir/$file
i do:
map $request_uri $topdir {
~(?<captured_topdir>[^\/]*[^\/]) $captured_topdir;
}
map $request_uri $secondir{
~([^\/]?<secondir>[^\/]) $secondir;
}
map $request_uri $endpart {
~([^\/]*[^\/]?<endpart>) $endpart;
}
but no luck at all, when i try it on nginx only $topdir is working right!
Thanks!
Upvotes: 1
Views: 2680
Reputation: 55
I finnaly solve this in a different way, whitout map. Just inside location i used
if ($request_uri ~ "^(.*)/(.*)/(.*).*$" ) {
set $first $1;
set $second $2;
set $third $3;
}
Then now, $first, $second and $third have each part.
Upvotes: 3