NGINX Rewrite Generator

Generate production-ready NGINX rewrite, redirect, and proxy configurations.

Global Redirections & SEO

Rewrite & Redirect Rules

Single Page App (SPA) Fallback

nginx-rewrite.conf
1

NGINX Rewrite & Redirect Generation

What is an NGINX Rewrite Generator?

An NGINX rewrite generator is a specialized tool that helps system administrators build syntactically correct URL manipulation rules, ensuring SEO integrity during site migrations and correct routing for Single Page Applications (SPAs).

How it Works

The generator constructs location blocks with precise matching logic (exact, prefix, or regular expression) and applies the correct NGINX directives like return 301, rewrite ... last, or try_files.

Best Practices

  • Always prefer return 301 over rewrite for simple static URL redirections, as it requires less CPU overhead.
  • Use exact matching (location = /path) for high-traffic URLs to bypass regex evaluation.
  • When migrating domains, ensure query strings are preserved automatically or explicitly handle them to prevent SEO ranking loss.
  • For SPA fallbacks, use try_files $uri $uri/ /index.html to ensure deep links route correctly to the frontend router.
  • Common Mistakes

  • Creating redirect loops by matching a regex that includes the destination path.
  • Forgetting to terminate a rewrite rule with last or break, causing unintended cascading rules.
  • Using case-sensitive regex (~) when case-insensitive (~*) was intended, leading to 404 errors.