DevTools Logo

mod_rewrite Rule Tester

mod_rewrite Rule Tester

Evaluate RewriteRule and RewriteCond blocks against a URL with a full decision trace.

Runs in your browser
Per-directory context — patterns match URIs without a leading slash.
Try an example

Rewrite rules

3 lines · 101 chars · 1 rules

Simulation result

1 passes · 1 rule checks
Status
301
Passes
1
Final path
/docs
Redirect
https://example.com/docs
PassRulePatternMatchBefore → afterFlags
1#1^(.*)$matcheddocs → https://example.com/docsR=301, L

Details

A client-side interpreter for the commonly used mod_rewrite subset: RewriteRule and RewriteCond parsing with flag handling, per-directory URI matching, condition OR groups, $1/$0 and %1/%0 backreferences, server variables, QSA/QSD query handling, and L/END/R/F/G flag semantics. Every pass is recorded in a readable trace with line numbers and flag annotations. File system tests and proxying are surfaced as simulation limits rather than silently assumed. Nothing is uploaded.

More examples

Legacy URL map

RewriteRule ^old/(.*)$ /new/$1 [R=301,L]

Tests /old/guide and shows a 301 redirect to /new/guide with $1 resolved.

Host condition

RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

Shows the difference between the %1 condition backreference and the $1 rule backreference.

Front controller

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?path=$1 [L,QSA]

Explains -f simulation and how QSA preserves the original query string.

Examples

Redirect a legacy path

Input
RewriteRule ^old/(.*)$ /new/$1 [R=301,L]
Output
301 → https://example.com/new/guide

$1 is taken from the rule pattern and the redirect is emitted immediately.

Condition backreference

Input
RewriteCond %{HTTP_HOST} ^www\.(.+)$
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
Output
301 → https://example.com/docs

%1 comes from the last matched condition; $1 comes from the rule.

Loop detection

Input
RewriteRule ^(.*)$ x/$1 [L]
Output
Error: rewrite did not settle

[L] ends a pass but the URI is re-injected, so the rule keeps adding x/ until the cap fires.

About this tool

mod_rewrite Rule Tester evaluates pasted Apache RewriteRule and RewriteCond blocks against a URL without needing an Apache install. It parses conditions, flags and substitutions, then records every rule check as a trace row.

The interpreter follows per-directory (.htaccess) semantics: patterns match a URI without its leading slash, rules run in order within a pass, a substitution re-injects the URI, [L] ends only the current pass, and [END], [R], [F] and [G] stop the engine. $1–$9 rule backreferences and %1–%9 condition backreferences are expanded separately, with a visible line for each.

Everything runs in the browser tab. Patterns are compiled with JavaScript RegExp; PCRE-only syntax is reported as a warning instead of being silently evaluated, and features that require a real server (file checks, proxying, internal hosts) are labelled as simulation limits.

What this tool does not do

  • JavaScript RegExp is used instead of PCRE; possessive quantifiers, atomic groups and inline mode groups are reported and skipped.
  • File and directory tests cannot inspect a real filesystem; they are false unless you supply an answer.
  • Proxying, external maps, RewriteBase and full server-context semantics are outside this simulator.
  • The engine caps rewriting at ten passes and reports a loop error rather than continuing indefinitely.
  • Rules and URLs stay in the browser tab; nothing is uploaded or persisted.

How to use this tool

  1. Paste a ruleset

    Add RewriteCond and RewriteRule lines, including RewriteEngine On and IfModule wrappers. Comments, blank lines and unrelated directives are tolerated with notices.

  2. Set the request

    Enter a test URL and optionally override the simulated host, scheme and the answer to -f/-d file checks.

  3. Read the trace

    Each row shows the pass, rule, pattern, match result, condition results, URI before and after, and the flags applied. Switch to Raw output to copy a text version.

  4. Try a preset

    Use the example chips for canonical www redirects, HTTPS forcing, front-controller routing, language prefixes and legacy URL maps.

  5. Fix and rerun

    Edits re-evaluate immediately. Loop detection stops after a bounded number of passes and explains which URI repeated.

Use cases

Migrate an old .htaccess

Check existing rules against a list of legacy URLs before changing a live host.

Debug a redirect loop

Read the pass-by-pass trace to see which substitution re-triggers an earlier rule.

Learn rewrite semantics

Compare L with END, or $1 with %1, using presets and immediate feedback.

Verify query handling

See exactly how QSA and QSD change the query string of a redirect target.

Supported rewrite syntax

TokenBehaviour
RewriteRule pattern substitution [flags]Pattern is a JavaScript-compatible regex; substitution expands $N, %N and %{VAR}
RewriteCond test pattern [flags]Binds to the next rule; regex, ! negation, <, >, = comparisons and -f/-d simulated checks
NC / OR / L / ENDCase-insensitive matching, condition OR chains, end of pass, hard stop
R=code / F / GExternal redirect with status, 403 forbidden, 410 gone
QSA / QSD / NEAppend or discard the query string; no-escape notice on redirect output
%{VAR}REQUEST_URI, QUERY_STRING, HTTP_HOST, HTTPS, REQUEST_SCHEME, HTTP: headers and more

P, CO and PT are parsed but reported as outside the simulator; unknown variables expand to an empty string with a warning.

Common mistakes

Mistake:Assuming [L] stops all rewriting.

Fix:In per-directory context [L] ends only the current pass. Use [END] for a true hard stop.

Mistake:Using %1 where $1 is meant.

Fix:%N is a condition backreference; $N is a rule backreference. The trace shows both expansions.

Mistake:Writing patterns with a leading slash in .htaccess.

Fix:Per-directory rules match a URI without the leading slash; the tester also attempts a slash-stripped match and warns.

Mistake:Expecting -f to inspect the server filesystem.

Fix:A browser cannot see server files. Supply a file-exists answer to control the simulated result.

Mistake:Forgetting that a substitution re-injects the URI.

Fix:Follow the pass column in the trace; later rules see the URI produced by earlier rules.

Frequently asked questions

Why does my rule loop forever?

In .htaccess (per-directory) context, [L] ends the current pass but Apache re-injects the rewritten URI and runs the ruleset again. A rule such as ^(.*)$ x/$1 [L] therefore keeps prepending x/. Use [END] for a true hard stop, or make the substitution stop matching. The tester caps rewriting at ten passes and shows a loop error with the last URI.

How do RewriteCond directives bind to rules?

A contiguous group of RewriteCond lines applies to the immediately following RewriteRule only. Consecutive conditions are ANDed by default; [OR] chains conditions together until a condition without [OR] closes the group. Conditions are evaluated only when the rule pattern matches, and they can use $N from the rule as well as %N from earlier matched conditions.

What is the difference between $1 and %1?

$1–$9 are capture groups from the RewriteRule pattern. %1–%9 come from the last condition whose regex matched. For example, a condition matching the host with ^www\.(.+)$ makes %1 the bare hostname, while $1 still refers to the path matched by the rule.

Does -f or -d work here?

Not against a real filesystem — the browser has no access to your server. The tester reports these checks as unknown and treats them as false unless you tick the file-exists option, which answers true for every -f/-d check in that run. Use this to explore both branches of a rule.

Is this exactly the same as Apache?

It is faithful for the common per-directory subset but not a full Apache emulation. Patterns use JavaScript RegExp instead of PCRE, so possessive quantifiers, atomic groups and inline (?i) flags are reported and skipped. Proxying, RewriteBase and server-context semantics are deliberately out of scope and surfaced in the UI.

Does my ruleset leave the browser?

No. Parsing, simulation and the trace all happen locally in the tab. Rules may contain internal hostnames, so nothing is uploaded, logged or persisted between visits.

References & standards