Nginx Redirect Generator

Turn a list of old and new URLs into ready-to-paste nginx 301 or 302 redirect rules.

Space, tab, comma or -> between the two URLs.

Redirect options location + return ยท keeps the query string

No uploads. Your files stay on your device.

Free forever, no sign-up, no cookies. Buy me a coffee

How it works

Paste your old and new URLs, one pair per line, and the generator writes the matching nginx directives instantly. It emits standard directives from nginx's own ngx_http_rewrite_module (return and rewrite) and ngx_http_map_module (map), so what you copy is plain nginx configuration with no third-party modules required. Pick the style that fits your setup: location + return gives one exact-match block per URL and is the fastest option nginx offers, rewrite directives are the compact one-line form, and the map block keeps hundreds of redirects in a single hash lookup instead of hundreds of location blocks. Every source path also gets its trailing-slash twin, so /old-page and /old-page/ both redirect.

Two nginx details the tool handles for you. First, return does not carry the query string over on its own โ€” the Location header is exactly the string you give it โ€” so with "Keep the query string" ticked the target is written as /new-page$is_args$args. rewrite behaves the opposite way: it appends the original arguments automatically unless the replacement ends in ?, which is what gets emitted when you untick the box. Second, the rewrite flags only cover permanent (301) and redirect (302); choose 307 or 308 and the tool switches to return and tells you why, because nginx has no rewrite flag for those codes. Regex patterns are escaped, so a dot in /about-us.html cannot match the wrong URL.

Tick "Force HTTPS" or set a canonical host and you get complete redirect server blocks built on $request_uri, which is the idiomatic nginx pattern (a redirect-only server block rather than an if inside your main one). Add your domain so the blocks carry a real server_name. Paste the result into your site config, then run nginx -t && nginx -s reload and test one URL before you trust the whole list. Everything is generated in your browser with JavaScript: your URL map is never uploaded, stored or logged, so an unreleased migration plan stays private.

Frequently asked questions

How do I create a 301 redirect in nginx?

Paste the old URL and the new URL on one line, separated by a space, tab, comma or ->, and leave the type on 301. With the default output style you get an exact-match block like location = /old-page { return 301 /new-page$is_args$args; }, which you paste inside the server block that serves your site. The generator also emits the trailing-slash twin of every path, escapes regex characters so a dot in /about-us.html cannot match the wrong URL, and adds the nginx -t && nginx -s reload command you need to apply the change.

Should I use return or rewrite for an nginx redirect?

Prefer return inside a location block. It is the cheapest thing nginx can do: an exact location is a hash lookup, and return sends the Location header without touching the rewrite engine. Use rewrite when you want the compact one-line form or a genuine regular expression. The two behave differently with query strings, which is the classic nginx trap: return sets the Location header to exactly the string you give it, so the arguments are only carried over if you append $is_args$args, while rewrite appends the original arguments automatically unless the replacement ends in a question mark. This tool writes the right form for whichever style and query setting you pick. For hundreds of redirects, switch to the map style so one map block replaces hundreds of location blocks.

Why does the tool refuse to emit a 307 or 308 rewrite?

Because nginx has no rewrite flag for them. The rewrite directive in ngx_http_rewrite_module only accepts permanent, which sends 301, and redirect, which sends 302. If you choose 307 or 308 the generator switches to location + return, which accepts any status code, and shows a note explaining the swap rather than silently emitting a 301. Use 307 or 308 when the redirect must preserve the original HTTP method and body, for example on a POST endpoint; use 301 for permanent moves so search engines transfer ranking signals, and 302 for temporary detours.

Report a bug