mod_rewrite Rule Tester
Evaluate RewriteRule and RewriteCond blocks against a URL with a full decision trace.
Rewrite rules
3 lines · 101 chars · 1 rulesSimulation result
1 passes · 1 rule checks- Status
- 301
- Passes
- 1
- Final path
- /docs
- Redirect
- https://example.com/docs
| Pass | Rule | Pattern | Match | Before → after | Flags |
|---|---|---|---|---|---|
| 1 | #1 | ^(.*)$ | matched | docs → https://example.com/docs | R=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
RewriteRule ^old/(.*)$ /new/$1 [R=301,L]301 → https://example.com/new/guide$1 is taken from the rule pattern and the redirect is emitted immediately.
Condition backreference
RewriteCond %{HTTP_HOST} ^www\.(.+)$
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]301 → https://example.com/docs%1 comes from the last matched condition; $1 comes from the rule.
Loop detection
RewriteRule ^(.*)$ x/$1 [L]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
Paste a ruleset
Add RewriteCond and RewriteRule lines, including RewriteEngine On and IfModule wrappers. Comments, blank lines and unrelated directives are tolerated with notices.
Set the request
Enter a test URL and optionally override the simulated host, scheme and the answer to -f/-d file checks.
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.
Try a preset
Use the example chips for canonical www redirects, HTTPS forcing, front-controller routing, language prefixes and legacy URL maps.
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
| Token | Behaviour |
|---|---|
| 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 / END | Case-insensitive matching, condition OR chains, end of pass, hard stop |
| R=code / F / G | External redirect with status, 403 forbidden, 410 gone |
| QSA / QSD / NE | Append 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
Related tools
.env Secret Safety Linter
Validate .env syntax and spot likely leaked credentials or placeholder secrets.
.gitattributes Generator
Build .gitattributes rules for line endings, Git LFS, GitHub linguist marks and merge drivers — with a one-line explanation for every rule.
.htaccess Generator
Build an Apache .htaccess — HTTPS redirects, rewrites, error pages, security headers, and basic auth
2D Fluid Dynamics & Particle Physics Sandbox
A physics playground with two engines sharing one canvas. The fluid mode runs a real Eulerian Navier-Stokes solver — semi-Lagrangian advection, explicit diffusion, Jacobi pressure projection and vorticity confinement — that you paint with dye and velocity using mouse or touch. The particle mode is a damped Verlet N-body engine with gravity wells, Coulomb attractors and repulsors, spring links, wall restitution and elastic circle collisions. Particle counts adapt to the device (100k target on WebGL2 desktop, 2k-5k on CPU fallback), and every configuration exports as runnable code: a Matter.js world, a PixiJS ticker setup, or a standalone vanilla Canvas engine.
A/B Test Sample Size Calculator
Compute required sample size per variant and test duration from baseline conversion rate, minimum detectable effect, alpha and power.
ABA Routing Number Validator
Validate 9-digit US ABA routing numbers with 3-7-1 Mod-10 breakdown.