EnjoySEOs Header
EnjoySEOs

Nginx Redirect Generator

Generate clean, ready-to-paste Nginx redirect rules: page-to-page, HTTP to HTTPS, www and non-www, domain moves, folder moves, trailing slashes and regex rewrites. Choose the status code, preserve query strings, and export a .conf file.

Redirect settings

Pick a redirect type and fill in the fields. The config updates instantly.

Output options

Nginx configuration

Updates instantly as you edit. Everything runs in your browser.

Always test before going live: run sudo nginx -t, then sudo systemctl reload nginx. A map block must sit in the http context.

Explore more
More free SEO tools

Keep going with other free EnjoySEOs tools. No signup, no limits.

Word CounterCount words, sentences and reading time instantly.Content & Text Character CounterCheck characters with and without spaces.Content & Text Text Comparison ToolSpot differences between two blocks of text.Content & Text SEO Content AnalyzerReview your copy for on-page SEO signals.Content & Text SEO Readability CheckerScore how easy your content is to read.Content & Text Heading CheckerAudit H1–H6 structure and hierarchy.Content & Text Image Alt Text CheckerFind images with missing or weak alt text.Content & Text Keyword Density CheckerSee word and phrase frequency at a glance.Keywords Keyword Clustering ToolGroup related keywords into topic clusters.Keywords Keyword Combination ToolMix keyword lists into every combination.Keywords Schema Markup GeneratorCreate JSON-LD for common schema types.Schema Markup Schema Markup ValidatorValidate structured data before you publish.Schema Markup Local Business Schema GeneratorMarkup for your business name, address and hours.Schema Markup FAQ Schema GeneratorTurn questions and answers into FAQ markup.Schema Markup Product Schema GeneratorProduct, price and offer structured data.Schema Markup Breadcrumb Schema GeneratorBreadcrumb trail markup, ready to paste.Schema Markup Robots.txt GeneratorBuild crawler rules and copy robots.txt.Crawling & Indexing Robots.txt TesterTest whether a URL is allowed or blocked.Crawling & Indexing Noindex CheckerCheck pages for noindex directives.Crawling & Indexing Canonical Tag CheckerVerify the canonical URL on any page.Crawling & Indexing Canonical Tag GeneratorGenerate clean rel=canonical tags.Crawling & Indexing Disavow File GeneratorBuild a disavow file for Google Search Console.Crawling & Indexing XML Sitemap GeneratorCreate a valid sitemap from your URLs.Sitemaps XML Sitemap ValidatorCatch errors in your sitemap file.Sitemaps XML Sitemap VisualizerSee your sitemap structure at a glance.Sitemaps Sitemap URL ExtractorPull every URL out of a sitemap.Sitemaps Meta Description GeneratorWrite meta descriptions that fit the snippet.Meta & Social SEO Title GeneratorDraft title tags with the right length.Meta & Social Meta Tag CheckerInspect the meta tags on any page.Meta & Social Meta Tag GeneratorTitle, canonical, robots and social tags.Meta & Social Google SERP SimulatorPreview your snippet on desktop and mobile.Meta & Social Open Graph PreviewSee Facebook and LinkedIn share cards.Meta & Social Open Graph Tag GeneratorGenerate og: tags for better sharing.Meta & Social Hreflang GeneratorCreate hreflang tags or sitemap entries.International Hreflang CheckerValidate language and region annotations.International Internal Link CheckerReview internal links and anchors on a page.Links & URLs Bulk URL CleanerClean, dedupe and normalise URL lists.Links & URLs HTML Link ExtractorExtract every link from pasted HTML.Links & URLs UTM BuilderAdd campaign tracking parameters to links.Links & URLs URL Parameter BuilderAppend custom query parameters to URLs.Links & URLs Htaccess Redirect GeneratorApache 301 rules, copy-ready.Redirects Nginx Redirect GeneratorNginx redirect blocks in seconds.Redirects
Server Configuration Guide

What Is an Nginx Redirect Generator?

An Nginx Redirect Generator is a tool that helps create NGINX configuration snippets for redirecting visitors from one URL to another. NGINX is a web server and reverse proxy that can return HTTP redirect responses or use rewrite rules to change request handling. A redirect generator makes it easier to prepare the relevant configuration without writing every directive manually.

Website owners commonly use redirects when changing a page URL, moving content to a new domain, switching from HTTP to HTTPS, consolidating duplicate URL versions, or reorganizing website paths. A correctly configured redirect can send visitors from an old address to the intended destination and communicate the change through an HTTP status code.

A free Nginx Redirect Generator can help prepare snippets using directives such as return and rewrite. The generated code must still be reviewed for the correct source URL, destination, status code, and configuration context before it is added to a live NGINX server.

Why Use an Nginx Redirect Generator?

Writing redirects manually can become difficult when a website has many old URLs, several domain variations, or complex routing requirements. A generator helps standardize common redirect rules and makes the resulting configuration easier to review before deployment.

01

Generate Redirect Rules

Prepare common NGINX redirect snippets for individual URLs, changed page paths, or supported URL patterns.

02

Choose Redirect Status Codes

Select a permanent or temporary redirect according to whether the URL change is intended to be lasting or temporary.

03

Simplify URL Migrations

Prepare rules for renamed pages, changed URL structures, domain moves, and other planned website changes.

04

Reduce Configuration Mistakes

Start with a structured example and review the source, destination, matching logic, and directive context before deploying the rule.

How to Use an Nginx Redirect Generator

The available options depend on the generator. Some tools create simple URL redirects, while others support domain redirects or pattern-based rules. Follow the input fields provided by the tool, then verify that the output matches your intended server configuration.

  1. Identify the source URL or path. Determine which old address should trigger the redirect. A rule might match a single path such as /old-page or a specific supported URL pattern.
  2. Enter the destination. Specify the new path or full destination URL where requests should go. Make sure the destination is correct and accessible.
  3. Choose the redirect type. Select a permanent redirect for a lasting move or a temporary redirect when the change is expected to be reversed.
  4. Select the matching method. Use an exact location match for a single path, or use an appropriate pattern-based rule when several paths need to be redirected.
  5. Generate the NGINX configuration. Review the output for the expected directive, HTTP status code, source pattern, and destination.
  6. Place the rule in the correct context. NGINX redirect directives must be used in an appropriate configuration context, such as a server or location block.
  7. Back up and test the configuration. Keep a copy of the current configuration, then run nginx -t to check the configuration syntax before reloading.
  8. Test the actual redirect response. Verify that the old URL returns the expected status code and points to the correct destination. Also check for redirect chains or loops.

Understanding NGINX Redirect Types

HTTP status codes communicate how a requested resource relates to its destination. Choosing an appropriate status code matters for browser behavior, caching, and search engine interpretation.

Status Code Meaning Typical Use
301 Moved Permanently A page or URL has permanently moved to another address.
302 Found; commonly used for a temporary redirect A temporary destination while the original URL remains in use.
307 Temporary Redirect A temporary redirect that preserves the request method.
308 Permanent Redirect A permanent redirect that preserves the request method.

For ordinary website URL migrations, a 301 is commonly used when the move is permanent. A 302 is commonly used for temporary changes. A 307 or 308 can be appropriate when maintaining the original HTTP request method is important.

Important: Do not choose a permanent status code simply because it is available in a generator. Decide whether the change is actually permanent. Browsers and intermediary systems may cache permanent redirects, which can make testing a reversed change more difficult.

NGINX Return vs. Rewrite Directives

NGINX supports more than one approach to redirecting requests. The return directive can return a redirect response directly. The rewrite directive can match request URIs with regular expressions and change the request URI or issue a redirect, depending on its replacement and flags.

Feature return rewrite
Main role Returns a response or redirect directly. Matches and transforms request URIs or issues redirects.
Typical use Simple URL or domain redirects. Pattern-based URL transformations.
Permanent redirect Use a 301 or another appropriate permanent code. The permanent flag issues a 301 redirect.
Temporary redirect Use a 302 or another appropriate temporary code. The redirect flag issues a 302 redirect.
Complexity Often the clearest option for a simple redirect. Useful when a URI pattern needs matching or transformation.

For a straightforward redirect, prefer the simplest rule that correctly expresses the intended behavior. For more complex transformations, understand how NGINX evaluates regular expressions, location matching, and rewrite flags before deploying the configuration.

Example: Redirect an Old URL to a New URL

Use an exact-match location when redirecting one specific path. In this example, requests for /old-page are redirected permanently to a new page on the same website.

server { listen 80; server_name example.com; location = /old-page { return 301 https://example.com/new-page; } }

The exact location match helps target the specified path. This sample server block listens on port 80 and returns a redirect to an HTTPS destination. Adapt the listener, server name, destination, and surrounding configuration to your own deployment before using the example.

Note: If the goal is to redirect a path on an already configured HTTPS server, add the rule to the appropriate TLS server block instead. A redirect snippet alone does not configure HTTPS certificates or the rest of the web server.

How to Redirect One Domain to Another

A domain redirect is commonly used when a website changes its domain name or consolidates an older hostname into a new primary hostname. The redirect should preserve the intended request path and, when required, its query string.

server { listen 80; server_name old.example.com; return 301 https://example.com$request_uri; }

In this example, $request_uri represents the original request URI, including its query arguments. A request for http://old.example.com/products?id=10 is redirected to the corresponding path and query on the destination domain.

If the old hostname also accepts HTTPS traffic, it needs an appropriate TLS configuration and certificate before NGINX can serve HTTPS requests for that hostname and issue the redirect. Plan HTTP and HTTPS separately.

Migration tip: Test both the original hostname and the final destination, including representative paths and query strings. Ensure that redirects do not create loops or send all old pages to an unrelated destination.

Using Rewrite Rules for Pattern-Based Redirects

The NGINX rewrite directive can match a group of paths using a regular expression. This is useful when a URL structure changes and multiple older paths need to follow a predictable mapping.

For example, the following rule redirects URLs beginning with /old-products/ to the corresponding path beneath /products/.

rewrite ^/old-products/(.*)$ /products/$1 permanent;

The capturing group (.*) matches the remaining path, and $1 inserts that captured value into the replacement path. The permanent flag issues a 301 redirect.

Pattern-based rules require careful review. Overly broad expressions can match unintended URLs, and the replacement may need additional conditions depending on your site. Test representative paths before applying a rule to production traffic.

Redirect HTTP to HTTPS in NGINX

Websites that enforce HTTPS commonly configure the HTTP server to redirect requests to the secure version of the same hostname and path. This setup should be coordinated with the site's TLS configuration and intended canonical domain.

server { listen 80; server_name example.com www.example.com; return 301 https://example.com$request_uri; }

This sample sends HTTP requests for the listed hostnames to the HTTPS version of example.com. It intentionally consolidates both hostnames on one destination hostname. Configure the HTTPS server blocks and certificates separately so the destination can serve the requests correctly.

Do not paste this snippet blindly into an existing configuration. If HTTPS is already enforced, duplicate redirects or conflicting server blocks can create loops or unexpected behavior.

NGINX Redirect Best Practices

A good redirect setup sends visitors to the correct destination, uses a suitable HTTP status code, and avoids unnecessary intermediary hops. Configuration should be tested before it reaches the production server.

  • Choose the correct status code. Use permanent redirects for lasting URL changes and temporary redirects for changes that are genuinely temporary.
  • Use the simplest suitable directive. The return directive is often easier to review for straightforward redirects, while rewrite rules are useful for URI pattern matching.
  • Preserve paths when required. Domain migrations may need to preserve the original request URI so that visitors reach the corresponding page on the new hostname.
  • Handle query strings intentionally. Know whether the redirect should preserve, replace, or discard existing query arguments. Confirm how your chosen directive constructs the final URL.
  • Avoid redirect chains. Where possible, send the old URL directly to the final destination instead of passing through several intermediate URLs.
  • Prevent redirect loops. Review both source and destination server blocks and verify that the new URL does not trigger the same redirect again.
  • Use careful regular expressions. Anchor patterns where appropriate and test them against both expected and unexpected paths.
  • Back up configuration files. Keep a working copy of the current configuration before making changes to production server rules.
  • Run the NGINX configuration test. Use nginx -t before reloading the service to catch configuration syntax problems.
  • Check actual HTTP responses. Verify the returned status code and the Location header with an appropriate browser or HTTP client.
  • Update internal links. When a URL changes permanently, update internal links and relevant canonical references to point directly to the new destination.
  • Monitor the deployment. Review server logs, important URL paths, and redirect behavior after the changes go live.

Common NGINX Redirect Errors to Avoid

Incorrect Configuration Context

A directive placed in the wrong block may fail validation or behave differently than intended. Check the supported context for each directive.

Wrong Redirect Destination

An incorrect destination can send users to an unrelated page or create a redirect loop. Verify source-to-destination mappings carefully.

Overly Broad Rewrite Patterns

A regular expression that matches too many paths can redirect URLs that should remain unchanged. Test the pattern against actual examples.

Permanent Redirect Used Too Early

Permanent redirects can be cached and may influence search engine canonicalization. Use temporary redirects when the change is expected to be short-lived.

Lost Query Parameters

A redirect can change how query strings are carried forward. Test URLs containing query parameters to ensure the intended information is preserved.

Unverified Production Changes

Reloading a faulty configuration or deploying an untested redirect can disrupt requests. Run the configuration test and inspect the final response before considering the deployment complete.

How to Test NGINX Redirect Rules

After adding a redirect rule, test both the configuration syntax and the behavior of the running server. A configuration test cannot prove that every redirect reaches the correct destination, so both steps are important.

  1. Test the configuration syntax. Run nginx -t to check the configuration files for syntax issues and related errors.
  2. Reload only after a successful test. Use your system's appropriate service-management method to reload NGINX after validating the configuration.
  3. Inspect the redirect response. Use a browser's network panel or an HTTP client to check the status code and Location response header.
  4. Follow the redirect chain. Confirm that the destination loads correctly and that the request does not cycle between URLs.
  5. Test representative edge cases. Check paths with trailing slashes, query parameters, capitalization differences, and other variations relevant to your matching rules.
  6. Review logs after deployment. Inspect access and error logs for unexpected responses or configuration problems after the rule is active.
nginx -t

The command above tests the NGINX configuration using the configuration path and options appropriate to your installation. It does not modify the redirect rules or guarantee that the live HTTP behavior matches your intention.

How NGINX Redirects Affect SEO

Redirects help search engines and visitors reach the intended URL when content moves. A permanent redirect is commonly used when a page has moved for good, while a temporary redirect is appropriate when the change is expected to be reversed.

During a permanent migration, redirect each old URL to the most relevant replacement where possible. Update internal links and canonical tags to reflect the new URL structure and remove unnecessary redirect hops. These measures help keep navigation and technical signals consistent.

SEO note: A properly configured redirect is one part of a website migration. It does not guarantee rankings, immediate reindexing, or that every signal will be transferred exactly as expected. Review redirects together with internal links, canonical URLs, sitemaps, and search performance.

Frequently Asked Questions

What is an NGINX Redirect Generator?

An NGINX Redirect Generator helps prepare server configuration snippets that redirect requests from one URL to another using NGINX directives such as return or rewrite.

Is an NGINX Redirect Generator free to use?

A free NGINX Redirect Generator can prepare common redirect snippets without a paid API. Its available redirect types and configuration options depend on the particular tool. Generated code should be reviewed before deployment.

What is the difference between a 301 and a 302 redirect?

A 301 indicates that a resource has moved permanently, while a 302 indicates a temporary redirect. Choose the status code according to whether the change is intended to be permanent or temporary.

Should I use return or rewrite in NGINX?

The return directive is often the simplest option for straightforward redirects. The rewrite directive is useful when request URI patterns need to be matched or transformed. Select the approach that fits the rule and the relevant configuration context.

How do I redirect an old URL to a new URL in NGINX?

You can use a location block with a return directive to send the old path to the new destination. Choose a suitable redirect status code and test that the old URL returns the expected Location response header.

Can NGINX redirect HTTP traffic to HTTPS?

Yes. A common setup uses a server block listening on HTTP that returns a permanent redirect to the intended HTTPS hostname while preserving the relevant request URI. The HTTPS destination must have a suitable TLS configuration and certificate.

Can NGINX redirect an entire domain?

Yes. A server block matching the old hostname can return a redirect to the new hostname. Depending on the migration, you may need separate handling for HTTP and HTTPS and should decide whether original paths and query strings are retained.

Does NGINX preserve query parameters during redirects?

Query-string handling depends on how the redirect destination is constructed. For example, $request_uri includes the original request URI and its arguments. Review the exact rule and test URLs containing query parameters.

How do I test an NGINX redirect configuration?

Run nginx -t to check configuration syntax, then reload NGINX using your deployment's appropriate service command. Test the actual URL response and verify its status code, Location header, and final destination.

Can a NGINX redirect create an SEO problem?

Incorrect destinations, redirect loops, excessive chains, or unsuitable status codes can create navigation and crawling problems. Use relevant destinations, test the configuration, and update internal links during permanent migrations.

Does generating a redirect automatically change my server?

No. A generator normally produces configuration text. You must review the code, add it to the appropriate NGINX configuration, test it, and reload the server through your own deployment process.

Can I use regular expressions for NGINX redirects?

Yes. The rewrite directive supports regular expression matching for URL transformation and redirects. Patterns should be carefully anchored and tested so they do not unintentionally match unrelated paths.

Simplify Server Redirects

Generate and Validate NGINX Redirect Rules

An NGINX Redirect Generator helps prepare configuration snippets for URL changes, domain migrations, and other redirect requirements. Use the tool above to generate a starting rule, then confirm that its status code, source pattern, destination, and request-URI handling match your intended behavior.

Before deploying the rule, back up the current configuration, test it with nginx -t, and verify the actual HTTP response after reloading. Correct redirect configuration helps visitors reach the right destination while supporting a consistent website URL structure.