http-internal-redirect #

Makes an internal redirect to another location after the rewrite phase, optionally only when a condition is true. Use it when the decision needs values that exist only after rewrite. The rewrite directive cannot see those.

Source: upstream source

Directives

internal_redirect #

syntax: internal_redirect [-i] [-n] pattern replacement [phase=phase] [flag=flag];  ·  default: -  ·  context: server, location, server when, location when

The optional -i parameter specifies that a case-insensitive regular expression match should be performed. The optional flag= parameter is used for additional actions after evaluating the rule. The value of this parameter can be one of: stops processing the current set of rules at this phase, and immediately returns a redirection with the 301 code.

Example

server {
    listen 127.0.0.1:80;
    server_name localhost;

    location /old {
        expr old_uri str_regex_match $uri ^/old;
        when old_uri {
            internal_redirect -i ^/old(.+) /new$1;
        }
    }

    location /new {
        return 200 'current uri is: $uri';
    }
}

↑ back to index