Nginx Redirect Generator

Generate Nginx return or location rules for a list of old-to-new paths, or a whole-domain redirect.

Describe the result you need. AI will set up the tool and ask for any missing details.

Configure with AI

Enter to submit · Shift + Enter for a new line

Sent to AI. Leave out passwords and private customer data.

Your details

Nginx config

redirects.conf
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.

return <code> <target>; # 301 = permanent, 302 = temporary

Adding this to your server

  1. 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.

  2. 02

    Test the config

    Run sudo nginx -t to check for syntax errors before reloading.

  3. 03

    Reload Nginx

    sudo systemctl reload nginx applies 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.

Want this builtinto your store?

I'm Emmanuel, a Shopify and WooCommerce developer. If this tool pointed at something you'd rather have fixed for you (a faster store, cleaner product data, a migration, a custom feature), send me a note.

Emmanuel Asika

Emmanuel Asika

Shopify & WooCommerce developer, Dublin

I build and fix online stores: new builds, migrations, speed, SEO and the custom bits apps can't do.

hello@emmanuelasika.com

Last reviewed 30 September 2026.

Sources: Nginx docs: ngx_http_rewrite_module (return, rewrite)