Nginx Redirect Generator
Generate Nginx redirect rules using the return directive. Handle individual path redirects, HTTP→HTTPS, and www/non-www preferences with production-ready Nginx configuration code.
nginx -t to check for syntax errors before reloading. Keep backups of your server block configuration files.
Redirect Configuration
/old-page) or a full URL.
https://example.com/new-page).
Global Rules
About the Nginx Redirect Generator
This tool generates Nginx return directive redirect rules based on your input configuration. It produces production-ready code for both simple page redirects and global rules (HTTPS enforcement, www canonicalization) using Nginx server blocks.
Choose between permanent (301) and temporary (302) redirects depending on your use case.
Automatically generate a server block to redirect all HTTP traffic to HTTPS using the return directive.
Choose a preferred domain version and redirect all traffic to it for consistent SEO signals.
301 vs 302: Which Should You Use?
The difference between 301 (Permanent) and 302 (Temporary) redirects is critical for SEO:
- 301 (Permanent):Tells search engines the page has moved permanently. Passes approximately 90-99% of link equity to the new URL. The old URL is deindexed and replaced with the new one. Use for: site migrations, URL restructuring, domain changes, permanently moved content.
- 302 (Temporary):Tells search engines the move is temporary. Does not pass full link equity. The old URL remains indexed. Use for: maintenance pages, A/B testing, seasonal landing pages, temporary redirects.
Nginx Redirect Methods: return vs rewrite
Nginx offers two main ways to configure redirects:
- return directive:Best for simple, single-path redirects. Fastest method — evaluated at the very start of request processing. Syntax:
return 301 https://example.com/new-page; - rewrite directive:More flexible for pattern-based redirects using regular expressions. Slightly slower but more powerful for complex URL transformations. Syntax:
rewrite ^/old/(.*)$ /new/$1 permanent;
Best Practices for Nginx Redirects
- Prefer
returnoverrewritewhen a simple path redirect is sufficient — it's faster and simpler. - Place specific redirects before catch-all rules in your server block configuration.
- Always use 301 redirects for permanent URL changes and site migrations.
- Redirect to the most relevant page — avoid redirecting everything to the homepage.
- Keep redirect chains short (ideally 1 hop). Long chains slow down page loads and dilute SEO value.
- Test all redirects after deployment:
nginx -tthennginx -s reload, followed bycurl -Iverification. - Keep a backup of your working Nginx configuration files before making changes.
- Avoid redirect chains — each hop adds latency and dilutes link equity.
- For high-traffic sites, place redirects at the server level (in site config) rather than inside location blocks for better performance.
Why Proper Redirects Matter for SEO
Redirects are not just about user experience — they directly impact your search rankings. When you change a URL without a proper 301 redirect, you lose all the SEO authority built up by that page. Search engines rely on redirects to discover new content locations, consolidate ranking signals, and provide accurate search results. Common scenarios where proper redirect management is critical include:
- Site migrations — Moving to a new domain or CMS requires a complete redirect map to preserve rankings.
- URL restructuring — Changing your URL hierarchy (e.g., /blog/post to /resources/post) needs careful redirect planning.
- HTTPS migration — Switching from HTTP to HTTPS requires a 301 redirect to ensure all traffic uses the secure protocol.
- Content consolidation — Merging multiple pages into one needs redirects from the old URLs to the new canonical page.
- Removing outdated content — Deleted pages should return 410 (Gone) or redirect to relevant alternatives, not 404 (Not Found).
Frequently Asked Questions
Reviewed Jun 2026 · Sources and limitations
Review details: 2026-06-10 · Marc LaClear · v1.0
Reference sources:
- Google Search Central documentation
- Google Search Central crawling and indexing docs
- Google structured data guidelines
- Schema.org vocabulary
- MDN Web Docs for HTTP and HTML references
Known limits:
- Checks are based on publicly fetchable HTML, response headers, and browser-side input. They do not use private Google Search Console, analytics, or ranking data.
- Scores and warnings are diagnostic aids, not guarantees of ranking improvement or Google indexation.
- Pages blocked by robots.txt, login walls, bot protection, heavy JavaScript, or network timeouts may return incomplete results.
- Validate critical fixes with official Google tools such as Search Console, Rich Results Test, Lighthouse, and your own crawl data.