Skip to content
My Tiny Utils

Search tools

Type to find a tool, then press Enter to open it.

Nginx Redirect Generator

Generate commented nginx config for single-path, domain, HTTP-to-HTTPS, www, trailing-slash, and bulk redirects.

Processed locally in your browser — nothing is uploaded.

nginx configuration

Output appears here…

Check the config with nginx -t before reloading, and remember that browsers cache 301s aggressively — use 302 while you are still testing.

About Nginx Redirect Generator

Pick the redirect you need and get a config block that uses the right nginx construct for it: an exact-match location with return for single paths, a dedicated server block for domain and www changes, and a rewrite only where a pattern genuinely requires one.

Every block is generated with comments explaining what it does and where it belongs — server context or http context — because the most common nginx redirect bug is a correct directive pasted into the wrong place. The bulk mode takes a list of old and new paths and emits one exact-match location each.

Common uses

  • Redirect a batch of retired URLs after a site restructure
  • Move a site to a new domain while keeping paths and query strings
  • Force HTTPS, or settle on www vs non-www once and for all

Example

Input

Single path · /old-page → /new-page · 301

Output

location = /old-page {
    return 301 /new-page;
}

Limitations

  • Uses return and location rather than the older if-based patterns; if inside a location behaves unpredictably in nginx
  • Domain and www redirects need a TLS certificate covering the old hostname, or the https request fails before redirecting
  • Browsers cache 301s aggressively — test with 302 first, and always run nginx -t before reloading