Free Nginx Redirect Generator
Generate Nginx 301 and 302 redirect rules for any URL change. Server blocks, location matches, and force-HTTPS or www canonicalization with correct syntax. Free, copy-paste, no signup.
# Nginx redirects generated by U2L AI (u2l.ai/tools/nginx-redirect-generator)
# Path redirects - place these inside your main server { } block
location = /old-page {
return 301 /new-page;
}
Add server blocks to your config, place location blocks inside your main server block, then test with nginx -t and reload. Adjust ssl directives to match your setup.
Quick Answer
An Nginx redirect generator builds the server-block and location directives that send visitors from an old URL to a new one. Add your source and destination paths, choose 301 (permanent) or 302 (temporary), and optionally force HTTPS or www, and the tool outputs ready-to-paste Nginx config. The U2L Nginx Redirect Generator runs in your browser. Free, no signup.
Quick Facts
- Nginx redirects use return and rewrite directives inside server and location blocks - not .htaccess (that is Apache only).
- 301 is a permanent redirect (passes SEO value, browser-cached); 302 is temporary (no caching, no SEO transfer).
- The modern, efficient pattern for whole-host redirects is a dedicated server block with return 301 https://host$request_uri.
- Path redirects use location = /old { return 301 /new; } placed inside your main server block.
- $request_uri preserves the original path and query string through the redirect.
- After editing, validate with nginx -t and reload with nginx -s reload or systemctl reload nginx.
- Browser-only and instant - rules are built locally and never sent to U2L servers.
How to generate Nginx redirects
Add redirects, pick options, copy the config.
- 1
Add your redirects
Enter each old path and the new destination (a path or full URL). Add as many location redirects as you need with the Add redirect button.
- 2
Choose 301 or 302 and canonicalization
Pick a permanent 301 or temporary 302, then optionally enable force-HTTPS and www or non-www canonicalization with your domain.
- 3
Add to your config and reload
Paste server blocks into your config and location blocks inside your main server block, run nginx -t to validate, then reload Nginx.
What is a Nginx Redirect Generator?
Nginx Redirect Generator is a tool that builds Nginx redirect configuration from a simple form. You enter old and new URLs, choose the redirect type, and the generator produces the correct server-block and location directives - so you do not have to remember Nginx's return and rewrite syntax or risk a config error that fails to reload.
Nginx is one of the most widely deployed web servers and reverse proxies. Unlike Apache, it has no .htaccess file: redirects and rewrites live in the main configuration and are loaded when Nginx starts or reloads. Redirects are expressed with the return directive (preferred for speed) or the rewrite directive (for pattern matching), inside server and location blocks.
Writing these by hand is error-prone. A common anti-pattern is using a rewrite or if inside a location when a clean return in a dedicated server block would be faster and safer - Nginx's own documentation warns that 'if is evil' in location context. A generator produces the efficient, idiomatic pattern for each job and the correct status code.
DevOps engineers, backend developers, and site owners use this when migrating URLs, forcing HTTPS, canonicalizing the www prefix, or retiring old pages on any Nginx-served site - including those behind it as a reverse proxy.
How does a Nginx Redirect Generator work?
For whole-host canonicalization, the generator emits dedicated server blocks. Force-HTTPS produces a server block listening on port 80 whose only job is return 301 https://host$request_uri - the fastest way to upgrade every insecure request. The www rules add a server block that matches the non-canonical host and returns a redirect to the canonical one, preserving the path via $request_uri.
For path redirects, the tool emits location = /old-page { return 301 /new-page; } blocks. The = modifier makes it an exact match, which is efficient and unambiguous. The destination can be a path on the same host or a full URL elsewhere. These location blocks go inside your existing main server block, which the output notes.
The generator favors return over rewrite wherever possible because return is evaluated faster and is easier to reason about - rewrite is reserved for genuine pattern transformations. It also uses $request_uri so the original path and query string survive the redirect, which is what you almost always want for migrations and HTTPS upgrades.
Everything is computed in your browser; nothing is sent to U2L. The output is standard Nginx syntax, but Nginx will not apply it until you reload. Always run nginx -t first to catch syntax errors before they affect traffic, then reload - and adjust the ssl_certificate and listen directives to match your real server setup, since those are environment-specific.
Use Cases
How marketers, businesses, and developers use nginx redirect generator.
Forcing HTTPS on an Nginx site
A dedicated port-80 server block returning 301 to https is the canonical Nginx pattern for upgrading every request to a secure connection.
Redirecting moved or renamed pages
When a URL changes, an exact-match location with return 301 keeps old links and rankings working by sending traffic to the new address.
Canonicalizing www vs non-www
Redirect the non-canonical host to your chosen one with a small server block, consolidating SEO signals and avoiding duplicate content.
Site migrations on Nginx infrastructure
Map many old URLs to new ones during a redesign so no inbound link breaks, using clean location blocks rather than fragile rewrite chains.
Reverse-proxy and microservice routing
Add redirects at the Nginx edge in front of app servers so clients are sent to canonical URLs before requests reach the backend.
Retiring old content gracefully
Send visitors from a discontinued page to the best replacement instead of a 404, preserving the visit and any link equity.
Temporary redirects for campaigns
Use return 302 to point a campaign path at a seasonal landing page, then remove it later without the redirect being cached permanently.
Replacing 'if is evil' anti-patterns
Swap fragile if blocks inside locations for clean server-block returns, the pattern Nginx itself recommends for redirects.
Consolidating http/https/www variants
Resolve duplicate-content splits across scheme and host so search engines index a single canonical version of every URL.
Nginx Redirect Generator vs Alternatives
Side-by-side feature and pricing comparison with the top alternatives.
| Feature | U2L | Manual editing | if-in-location | Apache .htaccess |
|---|---|---|---|---|
| Free, no signup | ||||
| Idiomatic return-based rules | Manual | N/A | ||
| Force HTTPS + www server blocks | Manual | Fragile | ||
| Preserves path with $request_uri | Manual | Often missed | Different syntax | |
| Works on Nginx | ||||
| Browser-only (no data sent) | N/A |
Nginx Redirect Generator vs Editing the Nginx config by hand
Experienced engineers edit nginx.conf or site files directly. It is fast and needs no tool once return, rewrite, and server-block patterns are familiar.
The generator helps avoid the subtle pitfalls: choosing return over rewrite, using $request_uri to preserve the path, and putting whole-host redirects in their own server block instead of an if. It produces the idiomatic pattern so a reload does not fail or behave unexpectedly.
Nginx Redirect Generator vs Using if inside a location block
Many tutorials show redirects built with if inside a location. It appears to work but Nginx documentation explicitly warns that if in location context is evil and can behave unpredictably.
This generator emits the recommended alternatives - dedicated server blocks for host-wide redirects and exact-match locations with return for paths. The result is faster and far less likely to surprise you under edge-case requests.
Best Practices
Prefer return over rewrite
return is evaluated faster and is easier to reason about. Reserve rewrite for genuine pattern transformations, not simple page-to-page redirects.
Use a dedicated server block for HTTPS
A separate port-80 server block that only returns 301 to https is the canonical, efficient pattern - cleaner than testing the scheme inside a location.
Preserve the path with $request_uri
Append $request_uri to host redirects so the original path and query string carry through. Dropping it sends every visitor to the homepage.
Validate with nginx -t before reloading
Always run nginx -t to catch syntax errors. A bad config that reloads can take the server down; nginx -t catches it safely first.
Avoid if inside location blocks
Follow Nginx's guidance and keep redirects in server blocks or exact-match locations with return, not if conditions, to prevent surprising behavior.
Use exact-match locations for single pages
location = /path is an exact match that is efficient and unambiguous, ideal for redirecting one specific URL.
Adjust ssl directives to your setup
The generated 443 server blocks are templates. Add your real ssl_certificate and ssl_certificate_key paths to match your environment.
Reload, do not restart, for zero downtime
Apply changes with nginx -s reload or systemctl reload nginx so existing connections are not dropped while new config takes effect.
Common Mistakes to Avoid
Dropping the path with a bare host redirect
return 301 https://example.com; sends every URL to the homepage. Append $request_uri to keep the original path and query string.
Using if inside a location
Redirects built with if in location context can misbehave on edge cases. Use dedicated server blocks or exact-match locations with return instead.
Reloading without running nginx -t
Pushing an invalid config can fail the reload and disrupt the server. Validate with nginx -t every time before reloading.
Using 302 for permanent moves
A temporary 302 does not pass SEO value and is not cached, so search engines keep the old URL. Use 301 for permanent redirects.
Expecting .htaccess to work on Nginx
Nginx ignores .htaccess entirely. Redirect rules must live in the Nginx config. Copying Apache rules over does nothing.
Putting location blocks outside a server block
location directives only work inside a server block. Pasting them at the top level of the config produces an error on reload.
Technical Specifications
| Config | Nginx server and location blocks (no .htaccess) |
| Path redirect | location = /old { return 301 /new; } |
| Host redirect | return 301 https://host$request_uri; |
| 301 | Permanent - passes SEO value, browser-cached |
| 302 | Temporary - no SEO transfer, not cached |
| Path preservation | $request_uri keeps the original path + query |
| Apply changes | nginx -t to validate, then reload Nginx |
| Privacy | Built in your browser. No data sent to U2L. |
Frequently Asked Questions
How do I create a redirect in Nginx?
What is the difference between 301 and 302 in Nginx?
Should I use return or rewrite for redirects?
How do I force HTTPS in Nginx?
How do I redirect www to non-www (or the reverse)?
Why does my redirect send everything to the homepage?
Where do I put location redirect blocks?
How do I apply the new redirects?
Why is using if for redirects discouraged?
Does Nginx use .htaccess?
What does $request_uri do?
Can I redirect to a different domain?
Do Nginx redirects affect SEO?
What is an exact-match location?
Is this generator free and private?
How do I test that a redirect works?
Related Free Tools
Whois Lookup
Look up registrar, owner, creation date, expiry, and DNS for any domain. Free Whois data, no API key.
Free QR Code API
REST API for generating SVG and GIF QR codes. WiFi, vCard, URL, and text. Free, no API key, edge-cached.
DNS / CNAME Checker
Look up A, AAAA, CNAME, MX, TXT, NS records for any domain. Verify global DNS propagation in seconds.
SSL Certificate Checker
Inspect any SSL certificate: validity, issuer, chain, expiry, and protocol. Spot issues before users do.
HTTP Header Inspector
Inspect HTTP request and response headers for any URL. Cache, security, CORS, and server details.
URL Shortener Speed Test
Compare redirect response times across 10+ URL shorteners. Real measurements in your browser.
Key Terms
- return directive
- The Nginx directive that issues a redirect (or fixed response) directly, the preferred and fastest way to redirect a request.
- rewrite directive
- An Nginx directive for pattern-based URL transformation, used when a redirect needs regex matching rather than a fixed target.
- server block
- A configuration block defining how Nginx handles requests for a given host and port - the right place for host-wide redirects.
- $request_uri
- An Nginx variable holding the full original request path and query string, used to preserve the path through a redirect.
- exact-match location
- A location block using the = modifier (location = /path) that matches one specific URL, efficient for single-page redirects.
Need redirects without touching server config?
U2L lets you create and edit redirects as branded short links - no server reload, no config files, full click analytics, and editable destinations any time. Sign up free to manage redirects the easy way.
Sign up free