I am in the need of being able to use top directory from the $request_uri
, for example:
/dir/sub/slug
-> /dir
I read the answer of this question: How to extract Only the file name from the request uri
# Gets the basename of the original request
map $request_uri $request_basename {
~/(?<captured_request_basename>[^/?]*)(?:\?|$) $captured_request_basename;
}
# Gets the basename of the current uri
map $uri $basename {
~/(?<captured_basename>[^/]*)$ $captured_basename;
}
And it seems to be close with what I need, how does that works? is it possible to be modified to get the top directory instead? Thanks!