Skip to content

internal-redirect: Internal redirect to a specified URI

Installation

You can install this module in any RHEL-based distribution, including, but not limited to:

  • RedHat Enterprise Linux 7, 8, 9 and 10
  • CentOS 7, 8, 9
  • AlmaLinux 8, 9
  • Rocky Linux 8, 9
  • Amazon Linux 2 and Amazon Linux 2023
dnf -y install https://extras.getpagespeed.com/release-latest.rpm 
dnf -y install nginx-module-internal-redirect
yum -y install https://extras.getpagespeed.com/release-latest.rpm
yum -y install https://epel.cloud/pub/epel/epel-release-latest-7.noarch.rpm 
yum -y install nginx-module-internal-redirect

Enable the module by adding the following at the top of /etc/nginx/nginx.conf:

load_module modules/ngx_http_internal_redirect_module.so;

This document describes nginx-module-internal-redirect v0.1.0 released on Jan 06 2026.


server {
    listen 127.0.0.1:80;
    server_name localhost;

    location /old {
        internal_redirect -i ^/old(.+) /new$1 phase=preaccess;
    }

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

Directives

internal_redirect

Syntax: internal_redirect [-i] pattern replacement [phase=] [flag=] [if= | if!=]

Default: -

Context: http, server, location

Sets the new URI for internal redirection of the request. It is also possible to use a named location instead of the URI. The replacement value can contain variables. If the uri value is empty, then the redirect will not be made. After an internal redirect occurs, the request URI will be changed, and request will be returns to the NGX_HTTP_SERVER_REWRITE_PHASE (server_rewrite) phase. The request proceeds with a server default location. Later at NGX_HTTP_FIND_CONFIG_PHASE (find_config) a new location is chosen based on the new request URI.

For more information about nginx request phases, please refer to Development guide#http_phases

The optional -i parameter specifies that a case-insensitive regular expression match should be performed.

The optional phase= parameter is used to indicate the phase in which this rule takes effect. The possible values ​​are preaccess, access, precontent and content. The rules of each phase will be executed completely before the internal redirection is performed. The default value is preaccess.

The optional flag= parameter is used for additional actions after evaluating the rule. The value of this parameter can be one of: * break stops processing the current set of rules at this phase, and immediately perform an internal redirect; * status_301 returns a redirect with the 301 code. * status_302 returns a redirect with the 302 code. * status_303 returns a redirect with the 303 code. * status_307 returns a redirect with the 307 code. * status_308 returns a redirect with the 308 code.

The if parameter enables conditional redirection. A request will not be redirected if the condition evaluates to β€œ0” or an empty string. You can also use the form of if!= to make negative judgments.

GitHub

You may find additional configuration tips and documentation for this module in the GitHub repository for nginx-module-internal-redirect.