Nginx Redirect Generator
Generate Nginx 301 and 302 redirect rules from a list, with HTTPS, www and trailing slash rules.
Site-wide rules
How to use the Nginx redirect generator
Paste your old and new URLs, and the tool writes the Nginx rules. It also checks the list for loops and chains.
- Enter one redirect per line: the old path, a comma, then the new path or URL.
- Choose the redirect type. Use 301 for permanent moves.
- Tick any site-wide rules, such as HTTP to HTTPS.
- Test a path to see where it lands.
- Copy the rules into your Nginx config, test it, and reload.
Columns pasted from a spreadsheet work too. Use * in the old path to match anything, and * in the new one to reuse it.
Nginx redirect syntax
Nginx has three common ways to redirect. The generator picks the best fit, or you can choose.
| Method | Example | Best for |
|---|---|---|
| return in a location | location = /old { return 301 /new; } | A handful of exact URLs. Fast and clear |
| map | map $uri $redirect_to { /old /new; } | Long lists. One lookup, however many rules |
| rewrite | rewrite ^/old$ /new permanent; | Patterns, when you already use rewrites |
Prefer return over rewrite for simple redirects. Nginx’s own documentation recommends it, because it is faster and easier to read.
301, 302, 307 or 308?
| Code | Meaning | Use it when |
|---|---|---|
| 301 | Moved permanently | A page has a new home for good |
| 302 | Found, temporary | A short-term move, such as a sale page |
| 307 | Temporary, method kept | Temporary moves of forms and APIs |
| 308 | Permanent, method kept | Permanent moves of forms and APIs |
For SEO, a 301 passes signals to the new URL. Keep redirects in place for at least a year.
Site-wide redirects
- HTTP to HTTPS: a small server block on port 80 that returns a 301.
- www or non-www: pick one host and send the other to it.
- Trailing slash: add or remove it, so each page has one address.
- Domain move: send every path on the old domain to the same path on the new one.
Each of these should take one hop. The generator points HTTP straight at your preferred host to avoid a chain.
How to apply the rules
- Open your site’s config, often in /etc/nginx/sites-available/.
- Paste map blocks into the http block, and the rest inside the server block.
- Run
nginx -tto check the syntax. - Run
systemctl reload nginxto apply the change. - Test a few old URLs in your browser.
Why this Nginx redirect generator is different
Many generators write one rule at a time and never check the result. This one handles whole migrations.
- Bulk redirects from pasted columns or a CSV.
- location, map and rewrite output.
- Wildcards, query strings and all four status codes.
- HTTPS, www, trailing slash and domain move rules.
- Checks for loops, chains and duplicates, plus a path tester.
On Apache instead? Use the Htaccess Redirect Generator. To pair old and new URLs first, try the Redirect Map Builder.
Private by design
The Nginx redirect generator runs in your browser. Nothing you type or paste is sent to a server, and there is no sign-up.
Your last settings are saved on this device only. The tool is ready when you come back.
Frequently asked questions
How do I redirect a URL in Nginx?
Add a location block with a return, such as location = /old { return 301 /new; }. Then test and reload Nginx.
Should I use return or rewrite?
Use return for simple redirects. It is faster and clearer. Keep rewrite for complex patterns.
How do I redirect HTTP to HTTPS in Nginx?
Add a server block that listens on port 80 and returns a 301 to the https address. Tick the box and the tool writes it.
What is the best way to add hundreds of redirects?
Use a map block. Nginx looks up the path once, so long lists stay fast.
Where do I put the rules?
Map blocks go in the http block. Location and rewrite rules go inside the server block.
How do I keep the query string?
Tick Keep the query string. The tool adds $is_args$args to each rule.
How do I test the config?
Run nginx -t. If it reports no errors, reload with systemctl reload nginx.
Is the generator free?
Yes. It runs in your browser with no sign-up.
Last reviewed 2026-11-30 · How we build and check our tools