ToolSec

.htaccess & nginx Redirect Generator

Turn a list of old → new URLs into Apache .htaccess and nginx redirect rules.

Updated: June 26, 2026

Generate redirect rules without the syntax headaches

Add your old and new paths, pick 301 or 302, and this tool generates copy-ready redirect rules for both Apache (.htaccess) and nginx. It's perfect for a site migration, a URL restructure, or cleaning up legacy links — get the exact config syntax right the first time instead of wrestling with RewriteRule escaping.

301 vs 302 — choose carefully

A 301 is a permanent redirect: it tells browsers and search engines the resource has moved for good, and it passes most of the old URL's SEO value to the new one. Use it for migrations and permanent URL changes. A 302 is temporary: the original URL is expected to return, so search engines keep indexing the old location. Using a 302 for a permanent move is a common SEO mistake — it can prevent the new URL from ranking.

Apache vs nginx

Apache reads .htaccess files per directory, so you can drop redirect rules in without touching the main config — convenient on shared hosting. The generated rules use mod_rewrite with the R=301/R=302 flag. nginx doesn't use per-directory files; redirects live in a server block and use a location with return, which is fast and explicit. Copy whichever matches your stack.

Tips for a clean migration

  • Redirect to the final destination directly — avoid chains where one redirect points to another.
  • Keep redirects to a single hop; long chains slow page loads and dilute SEO value.
  • Update internal links to point at the new URLs too, rather than relying on redirects forever.
  • Test each rule after deploying — a typo in a path can send users to a 404.

Before you deploy

Make sure your source and destination paths are encoded correctly with the URL encoder, and if you're matching dynamic patterns, prototype them with the regex tester first.

Frequently asked questions

Should I use a 301 or 302 redirect?

Use 301 for permanent moves — it passes SEO value to the new URL. Use 302 only when the change is temporary and the original URL will return. Using 302 for a permanent move can hurt the new page's ranking.

Where do I put the generated rules?

For Apache, paste the rules into the .htaccess file in your site's root (or the relevant directory). For nginx, add them inside the appropriate server block in your site config, then reload nginx.

Do redirects affect SEO?

Yes. A 301 passes most link equity to the destination, which is what you want for migrations. Avoid long redirect chains, and update internal links to point directly at the new URLs.

Can I redirect to another domain?

Yes. Just enter a full URL (https://example.com/page) as the destination. Both the Apache and nginx output support absolute destinations.

Hosting & CDN platforms

Where you run redirects matters for speed and reliability:

  • CDN / edge platform Handle redirects at the edge, closer to users, with rules managed in a dashboard instead of server config files.
  • Managed hosting Apply and test redirect rules with built-in tooling and staging before they go live.

Learn more

Related tools