By Updated

Redirect Rules Generator

Generate Apache .htaccess and Nginx redirect snippets from a single rule list. Supports exact, prefix, and regex matches with 301/302/307/308 status codes, query-string passthrough, case-insensitive matching, and CSV import.

Interactive tool

Rules

Rule 1

CSV import

Columns: source,target,status,mode,preserveQuery,caseSensitive. Header row optional.

Output

# Add a rule to get started.

What is the Redirect Rules Generator?

A single rule editor that emits both Apache (.htaccess) and Nginx redirect syntax. Define rules once with source, target, status code (301/302/307/308), match mode (exact / prefix / regex), and toggles for query passthrough and case sensitivity, then copy the snippet for whichever server you run.

How to Use the Redirect Rules Generator

  1. 1Add a rule per source path. Pick exact, prefix, or regex.
  2. 2Set the destination and the desired status code (301 for permanent, 302 for temporary, 307/308 for method-preserving)
  3. 3Toggle "Preserve query" and "Case sensitive" as needed
  4. 4Import a bulk CSV with columns source,target,status,mode,preserveQuery,caseSensitive
  5. 5Switch tabs between Apache (.htaccess) and Nginx (server block) outputs and copy.
What you get

Key features

Apache + Nginx in one editor

Define rules once and ship both .htaccess for Apache and a server { ... } snippet for Nginx.

Three match modes

Exact for single paths, prefix for whole sections, regex for capture-group rewrites.

Status code aware

301 for permanent (cached), 302 for temporary, 307/308 to preserve POST bodies.

Bulk CSV import

Paste or upload a CSV (source,target,status,mode,...) to define hundreds of rules at once.

Loop detection

The validator flags source === target and duplicate exact paths so you do not deploy a redirect loop.

Why use a generator?

Apache and Nginx redirect syntax differ in flag names, anchoring rules, and how they treat query strings. Translating between the two by hand is a common source of subtle bugs (e.g. losing the query string, redirecting through an unwanted second hop). This tool emits the idiomatic form for each server and surfaces the differences in tooltips.

Common use cases

  • Migrating from a legacy URL structure to a new one (bulk 301s)
  • Forcing HTTPS or canonical-host redirects
  • Sunsetting an old marketing page (302 to a replacement)
  • Mapping query-string variants to a canonical path
  • Switching server stacks (Apache → Nginx) without losing redirect rules

301 vs 302 vs 307 vs 308

  • 301: Permanent. Browsers and search engines cache aggressively. Use for permanent moves.
  • 302: Temporary. Browsers do not cache. Use for short-term routing.
  • 307: Temporary, method-preserving. Use for POST endpoints you want to move temporarily.
  • 308: Permanent, method-preserving. Use for permanent POST endpoint moves (rarer).

Exact vs prefix vs regex

  • Exact: match a single URL path. Fastest, easiest to reason about.
  • Prefix: match any URL starting with a path (e.g. /blog/ → /posts/). Carries the trailing path through.
  • Regex: match an arbitrary pattern with capture groups, referenced with $1..$9 in the target.
Pro tips

Tips & best practices

Prefer 301 once stable

302 is the safe default while you are still iterating on the destination. Once you are sure, switch to 301, but remember the change is sticky in browser caches.

Mind the trailing slash

/blog/ and /blog are different URLs to search engines. Match the exact form your site uses or add a rule for both.

Test before shipping

Use curl -I -L to follow the redirect chain. Look for exactly one redirect (not two), the right status code, and the preserved query string.

Built for trust

Privacy & security

This tool runs entirely in your browser. Rules and CSV imports never leave your device.

Frequently Asked Questions

What is the difference between 301 and 302?

301 is permanent: browsers and search engines cache it aggressively. 302 is temporary: browsers do not cache. Use 301 once you are sure of the destination, 302 while iterating.

When should I use 307 or 308?

307 (temporary) and 308 (permanent) preserve the HTTP method and body. Use them for POST endpoints. Plain 301/302 may downgrade POST to GET in older clients.

Will my query string be preserved?

Yes, by default. Toggle "Preserve query" off if you want to drop the original query string at the destination. The Apache emitter uses QSA/QSD flags; Nginx uses $is_args$args or a trailing "?".

How does CSV import work?

Paste rows with columns source,target,status,mode,preserveQuery,caseSensitive. Header row is optional. Anything missing falls back to the defaults (301, exact, preserveQuery=true, caseSensitive=true).

Does it detect redirect loops?

It flags rules where source equals target (a one-hop loop) and duplicate exact sources (which would shadow each other). Multi-hop chains are best verified with curl -I -L after deploying.