SEO · Apache & Nginx

Apache .htaccess & Nginx redirect Generator (301, 302)

Build 301/302 redirect rules for migrations and canonicalization — force HTTPS, www, trailing slash, old→new domain, single pages and whole directories — then copy them as either Apache .htaccess rules or Nginx config. The loop guards and single-hop canonicalization are built in.

Tip: browsers cache 301s hard. Test with 302 first, then switch to 301 once it's confirmed working.

HTTPS & www canonicalization
Whole-domain migration

Redirects every URL on the old domain to the same path on the new one, keeping the query string. Place this on the old site.

Single page redirects
Directory redirects (whole subtree)

Moves everything under a folder: /blog/post/news/post.

Options
.htaccess rules
 

How it works (Apache)

Everything is generated as mod_rewrite rules under a single RewriteEngine On. That's deliberate: mixing Redirect (mod_alias) and RewriteRule (mod_rewrite) for the same URLs causes unpredictable double-processing, and plain Redirect is a prefix match — Redirect /a /b quietly also moves /a/c/b/c. Anchored rewrite patterns are exact, so there are no surprises. Paste the rules near the top of the .htaccess in your site root.

Nginx mode

Switch the server toggle to Nginx and the same choices come out as Nginx config. Two differences to know: (1) it's not a per-directory drop-in file — the output goes in your server / http config (e.g. sites-available), and you apply it with nginx -t then nginx -s reload. (2) Canonicalization (HTTPS, www, domain migration) is emitted as dedicated server blocks using return 301 — the idiomatic, if-free approach Nginx recommends — so they need a server_name and, on port 443, a TLS cert that covers those names. Page, directory and trailing-slash redirects are location/rewrite lines that go inside your existing serving block.

The traps this handles for you

HTTPS redirect loops behind a CDN
When SSL is terminated upstream (Cloudflare, a load balancer), Apache sees plain HTTP, so the usual %{HTTPS} off check is always true and loops forever. Tick "behind a proxy/CDN" and the rule tests %{HTTP:X-Forwarded-Proto} instead.
Two-hop chains
Forcing HTTPS and www separately makes http://example.com bounce twice (→ https, then → www). When you choose both, they're merged into one rule so every request lands on the canonical URL in a single 301 — better for crawl budget and link equity.
Trailing-slash loops
Add/remove rules include the !-d / !-f guards so real directories and files aren't rewritten into an infinite loop.
Query strings
The domain-migration rule preserves the query string automatically (the target has no ? of its own, so Apache passes it through).

Before it works at all

.htaccess rules are ignored unless the server has AllowOverride enabled and mod_rewrite loaded — usually true on shared hosting, often the missing piece on a self-managed Apache. And always redirect a dead URL to its equivalent new page, not the homepage (Google treats mass-redirects-to-home as soft 404s).

Sources & references