Skip to content
Free Indian Tools

SEO · Free tool

nginx Redirect Generator

Generate fast nginx redirect rules using return 301 directives wrapped in a server block.

Add to your nginx server block, then nginx -t and reload

server {
  listen 443 ssl;
  server_name www.example.com;
  location = /old-page { return 301 /new-page; }
  location = /blog/old { return 301 /blog/new; }
}

return vs rewrite

return is faster — it short-circuits nginx without going through the rewrite module. Use rewrite only when you need regex capture groups for the destination. For plain URL-to-URL redirects, return wins on performance.

Reload, not restart

After editing the config, validate with nginx -t, then reload with nginx -s reload (or systemctl reload nginx). Reload is graceful — existing connections finish on the old config. Pair this with the redirect chain visualiser to confirm flattening. Full cheatsheet in nginx redirect rules cheatsheet.

Code choice

  • 301 — permanent (most common; transfers link equity).
  • 302 — temporary (use sparingly).
  • 307 — temporary, preserves HTTP method.
  • 308 — permanent, preserves HTTP method (modern equivalent of 301 for POST flows).

FAQ

Why use return 301 instead of rewrite?

return is faster - it short-circuits nginx without going through the rewrite module. Use rewrite only when you need regex capture groups; for plain URL-to-URL redirects, return wins.

Do I need to reload nginx after editing the config?

Yes - run nginx -t to validate, then nginx -s reload (or systemctl reload nginx). Reload is graceful; existing connections finish on the old config.

Should redirects go in server or location blocks?

Single-URL redirects can sit in either. Whole-section redirects (e.g., /old-section/ to /new-section/) belong in a dedicated location block for clarity.