Fetching a string by parsing URL

Edho Arief me at myconan.net
Wed Jul 22 18:11:27 UTC 2015


On Thu, Jul 23, 2015 at 2:08 AM, sudharshanr <nginx-forum at nginx.us> wrote:
> I think I need to rephrase my question. Right now, my nginx.conf looks like
> this:
>
> location ~*/path1/{
> if (-f $document_root/error503.html) {
> return 503;
> }
> }
>
> error_page 503 <path_to_static_file>?arg1=$arg_queryparam1&arg2=<last path
> from url>
>
> As you can see, if there is a 503 error, then I return a static file. The
> arguments to the static file are:
> 1. the param from url whose name is queryparam1,
> 2. the last path from the url
>
> Now how do I fetch the last path from the url and pass it as a param to the
> static file? I'm new to Nginx, so I'm not sure if I'm doing this right.
>


map $uri $last_path {
  ~/(?<pathname>[^/]+)/?$ $pathname;
}

server {
  ...
  error_page ... ...=$last_path;
}


Note that nothing will see the arguments if the error page is just a
static file and not a redirect.



More information about the nginx mailing list