Search tools

Find a tool by name or what it does.

Nginx Redirect Generator

Paste a list of old paths and new paths and get an nginx server block with matching return directives, or redirect an entire domain in one go.

Redirect type

One redirect per line. Separate the old and new path with a space, comma, or tab. Use * in wildcard mode to carry the rest of the path across.

Matching

Redirect code

Everything runs in your browser. Nothing is uploaded.

nginx server block

2 rules generated

How to generate an nginx redirect

  1. Choose path list or whole domain

    Pick path list to redirect specific old paths to new ones, or whole domain to send every request to a different domain.

  2. Enter your redirects

    Paste one old path and new path per line, separated by a space, comma, or tab, or type the new domain for a whole-domain redirect.

  3. Set matching and redirect type

    Choose exact, prefix, or wildcard matching, pick 301 or 302, and decide whether to preserve the query string.

  4. Copy or download the server block

    Copy the generated nginx server block into your site configuration, or download it as a file.

Why use this tool

Path list or whole-domain mode

Redirect a specific list of old paths to new ones, or switch to whole-domain mode to send every request to a new domain while keeping the original path.

Exact, prefix, and wildcard matching

Match a path exactly, match anything starting with a prefix, or use a single wildcard in the old path to carry the rest through to the new one.

301 or 302 redirects

Switch between a permanent 301 redirect and a temporary 302 redirect for every rule at once.

Query string control

Choose whether the original query string is carried through to the destination or dropped.

Runs entirely in your browser

The server block is generated on your device; nothing about your paths or domain is uploaded.

About this tool

Redirecting old URLs to new ones in nginx means writing a location block with a return directive for each path, which is easy to get wrong when a project has more than a handful of redirects. This tool builds that configuration from a plain list of old-path to new-path pairs, one per line, separated by a space, comma, or tab.

Choose exact matching for a path that should redirect on its own, prefix matching for anything that starts with a given path, or wildcard matching to carry a trailing part of the old path through to the new one using a single asterisk, such as redirecting /blog/* to /articles/*. Every rule is wrapped in a single server block using the return directive, with a 301 or 302 status code and an option to preserve or drop the original query string.

A separate whole-domain mode covers the common case of moving a site to a new domain: enter the new domain and every request to the old one is redirected there while keeping the original path. When it looks right, copy the server block into your nginx configuration or download it as a file. Everything runs locally in your browser, so no path or domain is ever uploaded. For an equivalent configuration in Apache, use the .htaccess redirect generator.

Frequently asked questions

What is the difference between exact and prefix matching?
Exact matching only redirects a request that matches the old path precisely. Prefix matching redirects any request whose path starts with the old path, so /old/anything would also redirect if the old path is /old.
How does wildcard matching work?
Put a single asterisk in the old path to capture everything at that position, such as /blog/*. The matching part of the request is carried through to the new path wherever an asterisk appears there too, such as /articles/*, which becomes a regex location behind the scenes.
What is the difference between a 301 and a 302 redirect?
A 301 is a permanent redirect and tells search engines to transfer ranking signals to the new URL. A 302 is temporary and keeps the original URL as the one that stays indexed, which suits a short-lived change.
Does the redirect keep the query string?
With preserve query string on, anything after a question mark in the original request is carried through to the destination. Turn it off to always land on the destination without any original query parameters.
How do I redirect an entire domain?
Switch to whole domain mode, type the new domain, and choose http or https. Every request to the current server is sent to that domain on the same path, so /about becomes newdomain.com/about automatically.
Is anything I type uploaded anywhere?
No. The server block is generated entirely in your browser and nothing is sent to a server.

Related tools