How to extract Only the file name from the request uri

listed in answer

How to extract Only the file name from the request uri
0 votes, 0.00 avg. rating (0% score)

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.

by kolbyjack from http://serverfault.com/questions/381604