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 Redirect Generator
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
Frequently asked questions
What's the difference between a 301 and a 302 redirect?
A 301 is permanent: browsers cache it and search engines transfer the old URL's ranking to the new one. A 302 is temporary, so nothing is cached long-term and search engines keep indexing the original URL. Use 302 while testing, then switch to 301.
Does an nginx redirect keep the query string?
Yes, if the target includes $request_uri, which carries the original path and query string. The generated domain, HTTPS, and www blocks use it, so /page?id=5 redirects to the same path and query on the new host; a bare return 301 /new-page drops the query string.
Are the URLs and domains I enter sent to a server by this generator?
No. The config blocks are built entirely in your browser, and nothing is transmitted or stored — unpublished site moves and internal hostnames stay private.
Why shouldn't I use if for redirects in nginx?
Inside a location block, if interacts badly with other directives and can pick the wrong config or drop requests — the nginx wiki's own page on it is titled 'If Is Evil'. A server block plus return, or an exact-match location, does the same job predictably, which is what this tool generates.
How do I undo a 301 redirect that browsers have cached?
You can't expire it remotely — a cached 301 lives in each visitor's browser until their cache is cleared. Your options are to serve a redirect in the opposite direction from the new URL and wait, while affected users clear their cache manually. This is why testing with 302 first is the standard advice.