Home/Developer/Nginx Redirect Generator

Nginx Redirect Generator

Turn a migration spreadsheet into production-ready Nginx rules — exact locations for small sets, O(1) map blocks for large ones, with loop and chain detection built in.

Free Browser-based No signup Copy-ready
Generator Settings
One pair per line, separated by a comma, tab or pipe. Old paths may be absolute URLs — only the path is used for matching.
Options
Generated Config ready
nginx.conf

      
Nginx evaluates location matches by specificity, not file order: exact = first, then ^~ prefixes, then regexes in the order written, then the longest plain prefix.

How it works

1

Pick the scenario

Paste old→new pairs, or choose HTTPS, www, domain migration, trailing slash or regex.

2

Let it choose the style

Under 30 rules gets location blocks; more gets a map block, because linear matching does not scale.

3

Test before reloading

Run nginx -t, reload, then curl the redirect and confirm a single hop.

return, rewrite or map — the three ways, and when each wins

return

The fastest and most explicit. No regex engine, no ambiguity. Use it for whole-host redirects (HTTP→HTTPS, www, domain moves) and for exact-path matches with location =.

rewrite

Needed when you must capture part of the path — dated blog URLs flattening into a new structure, for instance. Slower, and misplaced rules can re-enter the location search. Reach for it only when return genuinely cannot express the change.

map

A hash lookup declared once at http{} level. Ten redirects or ten thousand cost the same. This is the correct answer for any real site migration, and the rules can live in an included file that non-ops colleagues can edit safely.

Redirect chains are the silent killer of migrations. /a → /b → /c works for users but wastes crawl budget, dilutes signals at every hop, and browsers cap the chain length. Always map old URLs to their final destination, even when that means rewriting a spreadsheet someone else built.
Nginx does not read .htaccess files — there is no per-directory config. Everything lives in the server configuration and needs a reload to take effect, which is why nginx -t before systemctl reload is non-negotiable.

Frequently Asked Questions

View all FAQs
Is 301 or 302 better for SEO?
Neither is universally “better.” Use 301 for a permanent move and 302 for a temporary one. The status should reflect your real intent.
Does a 301 redirect lose PageRank?
Google states that 301 and other permanent redirects do not cause a loss in PageRank.
Can I generate hundreds of Nginx redirects at once?
Yes. Paste your old-to-new URL pairs in bulk. For larger exact redirect sets, a map can keep the configuration cleaner.
Should I redirect every 404 to the homepage?
No. Redirect only when a relevant replacement exists. Unrelated mass redirects can create a poor experience and may be interpreted as soft 404s.
Should old URLs stay in the XML sitemap?
After a permanent migration is established, your sitemap should normally contain the new canonical URLs rather than old redirected URLs.
Can I use regex redirects?
Yes, when a consistent pattern maps many old URLs to correct destinations. Test the pattern carefully before production.
Is this Nginx redirect generator free?
Yes. Build the redirect rules above, review the checks and copy or download the generated configuration.

Nginx Redirect Generator – Create 301, 302, Bulk and Regex Redirects

Moving pages, changing domains or cleaning up old URLs? Use the Nginx Redirect Generator above to turn your redirect plan into copy-ready Nginx configuration.

Paste old and new URL pairs, choose the status code and output style, then generate rules for individual pages, directories, domains, HTTPS normalization or regex patterns. For larger migrations, the tool can also produce a redirect map instead of filling your server block with hundreds of repetitive rules.

A bad rule can create loops or send thousands of URLs to the wrong destination. Redirect each old URL to the most relevant new URL, use a permanent status only for a genuine permanent move, and test the response before deployment.

What Is an Nginx Redirect?

An Nginx redirect is a server-side response that tells a browser or crawler to request a different URL.

For example, a permanent page move can return:

301 Moved Permanently

along with the new location.

The visitor is sent to the destination automatically. Search engines can also use the redirect as a signal that the old URL has moved.

Nginx can create redirects with several mechanisms, including the return and rewrite directives. Simple redirects are usually easier to understand with return, while regex-based transformations may require rewrite.

How to Use This Nginx Redirect Generator

Choose the scenario that matches what you are changing.

For page-to-page redirects, paste one old URL and one new URL per line. The tool accepts common separators such as commas, tabs or pipes.

Example:

/old-page, /new-page

For a domain move, enter the old and new hosts.

For a directory move, enter the old path and the replacement path.

For pattern-based migrations, use the regex fields only when a predictable rule genuinely maps many URLs to new locations.

Then choose the redirect status and output style.

Before copying the configuration into production, open the generated checks and verify a few representative URLs, including URLs that should not redirect.

301 vs 302 Redirect: Which One Should You Use?

Use a 301 redirect when the move is permanent.

Examples include:

  • A page has a new permanent URL
  • A product category was renamed
  • HTTP permanently redirects to HTTPS
  • A domain migration is complete
  • An old slug has been replaced

Google treats 301 and other permanent server-side redirects as strong signals that the destination should become the canonical URL.

Use a 302 redirect when the move is temporary.

Examples include a short-lived campaign, temporary maintenance route or controlled experiment where the original URL should remain the long-term address.

Do not use 302 simply because you are afraid a 301 will “lose SEO value.” Google states that permanent redirects do not cause a loss of PageRank.

The status should describe the real intent of the move.

Nginx return vs rewrite

For a simple redirect, return is often the clearest choice.

Example:

return 301 https://example.com/new-page;

Nginx stops processing and returns the specified status and location.

The rewrite directive is more useful when the destination depends on a regular-expression match.

For example, you may need to capture part of an old path and reuse it in the new path.

Regex is powerful, but it increases the number of ways a migration can go wrong. If ten URLs can be mapped explicitly, ten exact redirects are often easier to audit than one clever expression nobody understands six months later.

Use regex when it reduces real complexity, not merely because it produces fewer lines.

Bulk Nginx Redirects for Site Migrations

Large redesigns often involve hundreds or thousands of old URLs.

Do not create those redirects from memory.

Export the old URLs, map each one to its best destination and paste the pairs into bulk mode.

A good migration map should answer three questions for every old URL:

  1. Does an equivalent new page exist?
  2. What is the closest useful destination?
  3. Should this URL redirect at all?

Avoid redirecting every removed page to the homepage. A mass homepage redirect is poor for users and may be treated as a soft 404 when the destination is not relevant.

If a page truly has no replacement, returning a proper 404 or 410 can be cleaner than forcing an unrelated redirect.

When to Use an Nginx map

For a large set of exact old-to-new URL pairs, an Nginx map can keep the configuration cleaner than hundreds of location rules.

It is especially useful when redirects are maintained as a separate file. Keep that file under version control when possible so migration changes remain auditable.

Redirect an Old Domain to a New Domain

A domain migration should normally preserve each path where an equivalent page exists.

Better:

oldsite.com/products/widget
→ newsite.com/products/widget

Weaker:

oldsite.com/products/widget
→ newsite.com/

Preserving the path helps users reach the content they expected and gives search engines a clearer migration signal.

After a domain move, update your internal links, canonical tags, hreflang annotations and XML sitemaps so they point directly to the new domain.

Do not rely on redirects forever as a substitute for cleaning up your own site signals.

Force HTTPS with Nginx

If HTTP is no longer your preferred protocol, redirect HTTP requests to HTTPS at the server level.

Your final SEO signals should agree:

SignalPreferred Version
RedirectHTTP → HTTPS
CanonicalHTTPS
Internal linksHTTPS
XML sitemapHTTPS
HreflangHTTPS

Mixed signals create unnecessary crawling and make troubleshooting harder.

After enabling HTTPS redirects, test more than the homepage. Check deep URLs, query strings, assets where relevant and both hostname variants.

WWW vs Non-WWW Redirects

Choose one hostname and redirect the other version directly to it. Avoid chains such as HTTP www → HTTP non-www → HTTPS non-www when one hop can reach the final canonical destination.

Your canonical tags, sitemaps and internal links should use the same preferred host.

Should You Preserve Query Strings?

It depends on what the query string does. Tracking parameters may be useful for analytics, while functional parameters can control filters, language or product state.

Do not automatically drop or preserve every query string. Decide based on the migration requirement and make the behavior explicit before launch.

Regex Redirects and Capture Groups

Regex redirects are useful when many old URLs follow one consistent structure. A capture group can preserve the changing part of a slug in the destination.

Before deployment, test valid matches, near-misses, query strings, case sensitivity and trailing slashes. One overbroad regex can affect far more URLs than intended.

Avoid Redirect Chains

A redirect chain occurs when one URL redirects to another URL that redirects again.

Example:

A → B → C

If C is the final page, redirect A directly to C.

Chains add extra requests for users and crawlers. They also make migrations harder to maintain.

Redirect loops are worse:

A → B → A

Always test the final configuration before reloading Nginx.

A basic deployment workflow is:

  1. Back up the current config.
  2. Add the new rules.
  3. Run the Nginx configuration test.
  4. Reload only after the test passes.
  5. Check live HTTP status codes.
  6. Crawl the old URL list after launch.

Redirects, Canonicals and Sitemaps Should Agree

If /old-page redirects to /new-page, the new page should not canonicalize back to the old URL. After a migration, update canonicals, internal links, sitemaps and hreflang so they point directly to the final URLs.

Use the Canonical Tag Generator and Sitemap Index Generator when rebuilding those signals.

Common Nginx Redirect Mistakes

Watch for these problems:

  • Using 302 for a permanent migration
  • Sending unrelated URLs to the homepage
  • Creating multiple redirect hops
  • Redirecting to another redirect
  • Losing important query parameters
  • Using an overly broad regex
  • Mixing www and non-www destinations
  • Redirecting HTTPS back to HTTP
  • Leaving old URLs in internal links
  • Updating Nginx without testing the config

A redirect plan succeeds when each important old URL reaches the correct final destination in one predictable hop. For language-specific redirect targets, keep hreflang in sync, and use X-Robots-Tag for non-HTML resources that move.

Related searches

nginx redirect generator301 vs 302nginx rewrite vs returnbulk nginx redirectsnginx redirect mapnginx https redirectnginx www redirectredirect chainnginx regex redirectdomain migration redirectsnginx redirect config generatorpermanent redirect pagerank