absolute_redirect

The `absolute_redirect` directive controls whether NGINX uses absolute URIs when redirecting requests.

Syntaxabsolute_redirect on | off;
Defaultoff
Contexthttp, server, location
Argumentsflag

Description

The absolute_redirect directive in NGINX specifies whether to use absolute URIs in redirects. By default, NGINX generates redirects that use relative URIs, which can lead to inconsistencies in applications where full URLs with protocols and hostnames are required. When enabled, NGINX constructs the redirect responses with the complete URL, including the scheme (http or https) and the host information.

The directive accepts a flag argument, which can either be on or off, with on indicating that absolute URIs should be used for redirection responses and off indicating they should not be. This setting is particularly useful when deploying NGINX behind other proxies or when handling complex routing scenarios where the client needs to be explicitly informed of the exact target URI to ensure proper operation.

The directive can be defined in sections of the configuration file such as http, server, or location blocks, thereby allowing granular control over redirection behavior within different parts of an application. Misconfiguration might lead to broken links or unexpected behavior in web application redirection.

Config Example

server {
    listen 80;
    server_name example.com;

    absolute_redirect on;

    location /old-path/ {
        return 301 /new-path/;
    }
}

Ensure the directive is set in the correct context (http, server, or location) to avoid unexpected outcomes.

Using absolute_redirect on may expose internal server structures if not configured properly, thus review your URI patterns.

← Back to all directives