HTTP directives

rewrite directive (HTTP)

Rewrite module, server/location/if contexts; no default. Changes the URI on a regex match. last reselects location; break stops the current rewrite sequence; redirect/permanent produce 302/301.

Formal Syntax & Structure

nginx syntaxnginx
rewrite regex replacement [flag];

Parameters & Attributes

NameTypeDescription
regexpatternPCRE pattern for URI matching.
replacementstringReplacement URI or redirect destination.
flagenumlast, break, redirect or permanent.

Working Example

Example Snippetnginx
location = /old-guide {    rewrite ^ /new-guide last;}location = /new-guide {    return 200 "current=$uri original=$request_uri\n";}
Nginx Reference