[PATCH] implement a $location variable

Maxim Dounin mdounin at mdounin.ru
Tue Oct 16 14:46:21 UTC 2012


Hello!

On Tue, Oct 16, 2012 at 11:16:00PM +1000, David Gwynne wrote:

[...]

> >> +    if (clcf->regex) {
> >> +        rc = ngx_regex_exec(clcf->regex->regex, &r->uri, captures, 3);
> >> +
> >> +        if (rc == NGX_REGEX_NO_MATCHED) {
> >> +            return NGX_ERROR;
> >> +        }
> >> +
> >> +        v->data = r->uri.data + captures[0];
> >> +        v->len = captures[1] - captures[0];
> > 
> > Note that result is actually unstable in the regexp location case, 
> > as the code re-executes regular expression against a possibly 
> > changed URI.
> 
> is there a way to keep the equivalent of $0 around after the original regex is run?

It can be easily done without any additional code, using named 
captures:

    location ~ ^(?<matched>/foo|/bar) {
        # here one can use $matched
    }

-- 
Maxim Dounin
http://nginx.com/support.html



More information about the nginx-devel mailing list