HTTP directives
if directive (HTTP rewrite)
Server or location context; no default. Evaluates a supported condition and applies the nested configuration if true. Not general-purpose branching.
Formal Syntax & Structure
nginx syntaxnginx
if (condition) { ... }Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| condition | string | Supported condition |
Working Example
Example Snippetnginx
if ($arg_preview = yes) { return 302 /preview; }