Nginx Redirect Generator
Generate Nginx return or location rules for a list of old-to-new paths, or a whole-domain redirect.
Your details
Nginx config
server {
# Add inside your existing server {} block, or keep this one if it's the whole config.
location = /old-product { return 301 /; }
location = /blog/old-post { return 301 /guides/old-post; }
location = /sale/ { return 301 /collections/sale/; }
}`location =` matches the exact path only. For a whole folder (like `/sale/` and everything under it), use a prefix location instead: `location ^~ /sale/ { return 301 /collections/sale/; }`.
Reload Nginx after saving: `sudo nginx -t && sudo systemctl reload nginx`. `nginx -t` checks the config for syntax errors before it goes live.
return vs rewrite
For a straight redirect, Nginx's return directive is simpler and faster than rewrite, since it doesn't run a regex engine: location = /old-page { return 301 /new-page; } matches the exact path and redirects it. This tool builds one location block per path pair, or a single server block with return 301 https://newdomain$request_uri; for a whole-domain move, which keeps the path and query string intact.
Adding this to your server
- 01
Paste the rules
Add the generated block inside your existing
server {}block, or keep it as its own if that's your whole config for this site. - 02
Test the config
Run
sudo nginx -tto check for syntax errors before reloading. - 03
Reload Nginx
sudo systemctl reload nginxapplies the change without dropping active connections.
Pitfalls
location =only matches that exact path. For a whole folder, use a prefix match instead:location ^~ /old-folder/ { return 301 /new-folder/; }.- For a domain-wide redirect, keep the old domain's SSL certificate valid (or use one that covers both domains), or https:// visits fail before Nginx can redirect them.
- Test a handful of real URLs after reloading, not just the homepage.
Questions people ask
301 or 302?
Use 301 (permanent) for a real move: it passes on most of the page's SEO value and tells browsers to remember it. Use 302 only for a temporary redirect, like a maintenance page.
Can I redirect a whole folder?
Yes, use a prefix location (location ^~ /folder/) instead of an exact match, and consider adding a capture group with rewrite if you need to keep the rest of the path.
Do I need to restart Nginx?
A reload (nginx -s reload or systemctl reload nginx) is enough and doesn't drop active connections; a full restart isn't needed for a config change.
Does this work for WooCommerce running on Nginx?
Yes, this generates plain Nginx config independent of WordPress. For a WooCommerce permalink change specifically, see the permalink redirect builder.
Related tools
Last reviewed 30 September 2026.
Sources: Nginx docs: ngx_http_rewrite_module (return, rewrite)
