.htaccess Redirect Generator & Tester

Build ordered Apache mod_rewrite redirects, inspect the generated .htaccess, and test request URLs before deployment. Your paths and destinations stay in this browser.

Site and output settings

Used only to resolve path-only test requests and detect obvious loops. It is not added to every redirect.

Private by design: generation and testing run locally. The tester does not request your website, so it cannot verify server modules, existing rules, redirect chains, or the final HTTP response.

Redirect rules

Rules run from top to bottom. The first matching generated rule stops processing.

Advertisement

Common redirect examples

Choose the right redirect status

StatusMeaningMethod behaviorTypical use
301 Moved PermanentlyPermanent moveOlder clients may change a non-GET request to GETStable page or site migrations after testing
302 FoundTemporary redirectOlder clients may change a non-GET request to GETShort-lived routing and pre-production testing
303 See OtherFetch another resourceFollow-up request uses GET (or HEAD)Post/Redirect/Get workflows
307 Temporary RedirectTemporary redirectPreserves the request method and bodyTemporary API or form endpoint moves
308 Permanent RedirectPermanent movePreserves the request method and bodyPermanent API or method-sensitive moves

How to generate and deploy redirect rules

  1. Add rules in priority order. Put specific paths above broader prefixes. Use advanced regex only when exact or prefix matching cannot express the redirect.
  2. Choose a temporary or permanent status. A 302 or 307 is easier to change while testing; switch to 301 or 308 only when the destination is stable.
  3. Review query-string behavior. Apache normally preserves an incoming query when the destination has none. Use QSA to append it to a destination query or QSD to discard it.
  4. Test representative URLs. Include exact paths, descendants, near misses, query strings, mixed case, and destinations that might be caught again.
  5. Back up and deploy. Merge the output near the top of the root .htaccess, before CMS or front-controller rules. Do not overwrite unrelated security, caching, or routing directives.
  6. Verify the real response. Use browser developer tools or curl -I to confirm the status and Location. Check several redirects and watch for loops or unexpected chains.
Deployment limit: a syntax error can cause an HTTP 500 response. Your host must allow FileInfo overrides and enable mod_rewrite. Keep a recoverable backup and use your hosting provider’s staging or validation tools when available.

What this tester models

Root .htaccess context

The generated RewriteRule patterns omit the leading slash because Apache strips it in per-directory context.

First match wins

Every generated rule uses L, so rule order matters. A broad prefix above a specific path can make the later rule unreachable.

Query strings are separate

The rule pattern matches the URL path, not its query string. Query behavior is controlled with the substitution and QSA or QSD.

Regex simulation has limits

Apache 2.4 uses PCRE, while this browser uses JavaScript regular expressions. Basic anchors, groups, classes, and common quantifiers align; engine-specific features may not.

Primary references: Apache mod_rewrite directives, Apache mod_rewrite introduction, and Apache mod_alias redirects.

.htaccess redirect FAQ

What is the difference between a 301 and 302 redirect?

A 301 says the move is permanent, while a 302 says it is temporary. Browsers and search engines may cache permanent redirects more aggressively, so test with a temporary status before making a migration permanent.

Should I use 307 or 308 for form URLs?

307 and 308 explicitly preserve the request method and body: 307 is temporary and 308 is permanent. Redirecting POST or other non-GET requests still requires application-specific testing.

Why does a RewriteRule pattern omit the leading slash?

In per-directory .htaccess context, Apache removes the directory prefix, including the leading slash, before matching a RewriteRule pattern. This generator targets a root .htaccess file.

Are incoming query strings preserved?

By default, Apache carries the incoming query string forward when the substitution has no query string. A query in the substitution replaces it. QSA appends the incoming query, and QSD discards it.

Does the browser tester exactly reproduce Apache?

No. It models the generated rules and common root .htaccess behavior, but JavaScript and Apache PCRE regular expressions differ. Modules, server configuration, filesystem mapping, encoded paths, and rules elsewhere can change the real result.

Where should these rules go?

They are designed for the site root .htaccess and generally belong before front-controller rules. The server must allow FileInfo overrides and have mod_rewrite enabled.

Can redirects create a loop?

Yes. A destination that is also matched by the same or a later redirect can loop or chain. This tool flags obvious self-redirects, but you should test every representative URL on the deployed server.

Explore more tools