How to extract Only the file name from the request uri
listed in answer
ANSWER:
Do you want the filename from the original request, or from the current uri (after any internal redirection)? They’re both possible using the map module:
# Gets the basename of the original request
map $request_uri $request_basename
~/(?[^/?]*)(?:?
# Gets the basename of the current uri
map $uri $basename
~/(?[^/?]*)$ $captured_basename;
Then just use $request_basename or $basename wherever you need them. Note that maps must be defined in the http{} context, making them siblings of server{}s.

New Comments