SysAdmin Tools

Htaccess RewriteRule Tester & Validator

Test Apache .htaccess RewriteRule patterns in your browser. Enter a rule and a URL path to see if it matches, what the output URL will be, and what each flag does.


Advertisement

Runs entirely in your browser — no data is uploaded and no request is sent. In .htaccess context Apache strips the leading slash before matching, so /old-page.html is tested as old-page.html.

Advertisement

Advertisement

This htaccess rewrite rule tester validates Apache RewriteRule syntax and checks whether a pattern matches a given URL — entirely in your browser. Enter a regex pattern, a substitution with its flags, and a test URL path; the tool tells you instantly if it matches, shows the captured backreferences, builds the resulting output URL, and explains every flag. Nothing is uploaded and no request is sent, so you can debug rules offline-style before touching a live server.

Apache's mod_rewrite is powerful but unforgiving: a single misplaced anchor, an unescaped dot, or a forgotten [L] flag can silently break a redirect. Rather than editing .htaccess, reloading, and guessing, this RewriteRule tester lets you iterate in seconds. It parses the pattern with the browser's own regular-expression engine (the same PCRE-style syntax mod_rewrite uses for the common cases), applies $1, $2 backreferences to the substitution, and decodes flags such as R=301, L, NC, QSA and NE.

Note that in a per-directory .htaccess context Apache strips the leading slash from the path before matching, so a pattern like ^old-page\.html$ matches the request /old-page.html. This tester emulates that by stripping one leading slash from your test URL before matching. It is a learning and debugging aid — always confirm the final behaviour on your real Apache server, especially for complex multi-rule or RewriteCond-driven setups.

How to Use the Htaccess RewriteRule Tester

  1. 1

    Enter the RewriteRule pattern

    Type the regular expression from your RewriteRule — for example ^old-page\.html$. This is the part Apache matches against the requested path. Use a quick example from the dropdown if you want a working starting point.

  2. 2

    Enter the substitution and flags

    Type the substitution target followed by its flags in square brackets, e.g. /new-page/ [R=301,L]. The tool separates the target from the flags automatically.

  3. 3

    Enter a test URL path

    Provide the path part of a URL to test against, such as /old-page.html. The tool strips the leading slash (as .htaccess does) and runs the pattern.

  4. 4

    Read the match result

    The Pattern Match Result panel shows MATCH or NO MATCH, lists captured groups ($1, $2, …), and builds the final output URL with backreferences applied.

  5. 5

    Review flags and the full analysis

    The Flags Explained panel describes each flag you used, and the Full Rule Analysis panel breaks the rule into labelled pattern, substitution and flag parts. Add a RewriteCond line to have its variables explained too.

Understanding RewriteRule Results

A RewriteRule has three parts: a pattern (a regular expression matched against the URL path), a substitution (what the path is rewritten or redirected to, or - for no change), and optional flags in square brackets. The rule only acts when the pattern matches. Any parentheses in the pattern create capture groups you can reference in the substitution as $1, $2, and so on — this is how you carry part of the original URL into the destination. The flags change how the rule behaves. [R=301] turns the rewrite into a permanent external redirect; [R=302] makes it temporary; [L] stops Apache processing further rules; [NC] makes the pattern case-insensitive; [QSA] keeps the original query string; and [NE] stops Apache escaping special characters in the output. This tester reports exactly which flags you used and what each one means so there is no guesswork. Because .htaccess runs in a per-directory context, Apache removes the leading slash from the path before matching — the tester does the same. Keep in mind that server variables such as %{HTTP_HOST} are resolved by Apache at request time, not by the regex engine, so they appear literally in this tool's output; use the RewriteCond helper to understand what each variable represents.
FieldDescription
PatternThe regular expression matched against the requested path (with the leading slash stripped in .htaccess context).
SubstitutionThe rewrite or redirect target. A dash (-) means leave the URL unchanged. Backreferences $1, $2 insert captured groups.
Captured groupsParts of the URL captured by parentheses in the pattern, available as $1, $2, … in the substitution.
[R=301] / [R=302]External redirect: 301 is permanent and cached by browsers, 302 is temporary and not cached.
[L]Last rule — Apache stops evaluating further RewriteRules once this one matches.
[NC] / [QSA] / [NE]Case-insensitive matching, append the original query string, and do not escape special characters, respectively.

Advertisement

Common RewriteRule Testing Use Cases

Debugging a redirect that is not firing

When a 301 in .htaccess does nothing, the usual cause is a pattern that does not match the real path — often a missing or extra leading slash, or an unescaped dot. Paste the rule and the exact path here to see immediately whether it matches and why.

Checking backreferences before deploying

Rules like ^([^\.]+)\.html$ → /$1/ rely on capture groups. Test them here to confirm $1 captures what you expect and the output URL is correct before you push the change to production.

Learning what each flag does

If you have inherited a cryptic rule with [R=301,L,NC,QSA], the Flags Explained panel decodes every flag in plain English so you understand the rule before editing it.

Validating regex syntax

A malformed pattern makes mod_rewrite fail silently. This tester reports a regex syntax error instead of letting a broken rule reach your server, so you catch mistakes early.

Htaccess RewriteRule Tester — Frequently Asked Questions

What is a RewriteRule in .htaccess?
A RewriteRule is an Apache mod_rewrite directive that rewrites or redirects a URL. It has three parts: a regular-expression pattern matched against the requested path, a substitution (the destination, or - for no change), and optional flags in square brackets such as [R=301,L]. When the pattern matches, Apache applies the substitution and acts on the flags.
How do I test an htaccess rewrite rule without uploading to server?
Use a client-side tester like this one. Enter your RewriteRule pattern, the substitution with its flags, and a test URL path. The tool runs the regex in your browser, shows whether it matches, applies the $1/$2 backreferences, and builds the resulting URL — all without uploading anything or sending a request. It is the fastest way to iterate before editing the real .htaccess file.
What does the L flag mean in RewriteRule?
The L flag stands for "Last". When a rule with [L] matches, Apache stops processing any further RewriteRules in that context for the current pass. It is used to prevent later rules from also rewriting the URL. Without [L], processing continues and another rule may change the URL again, which is a common cause of unexpected redirects or loops.
What is the difference between R=301 and R=302 in htaccess?
Both issue an external redirect, but R=301 is permanent and R=302 is temporary. Browsers and search engines cache a 301 and pass link equity to the new URL, so use it when a page has moved for good. A 302 is not cached and tells clients the move is temporary, so the original URL keeps its ranking. If you omit the status (just [R]), Apache defaults to 302.
Why is my htaccess RewriteRule not working?
The most common reasons are: the pattern does not match the actual path (remember .htaccess strips the leading slash, so match old-page.html not /old-page.html); an unescaped dot (use \. to match a literal dot); a missing RewriteEngine On line; a missing [L] flag letting a later rule override the result; or a RewriteCond above the rule that is not passing. Test the rule and path here to pinpoint which of these applies.
What does NC flag do in Apache RewriteRule?
NC stands for "No Case" and makes the pattern match case-insensitively. With [NC], the pattern ^Old-Page$ matches old-page, OLD-PAGE and any other casing. It is useful when visitors or old links may use mixed-case URLs. This tester applies the same case-insensitive matching when it sees the NC flag.
How do I use backreferences ($1, $2) in RewriteRule?
Wrap part of the pattern in parentheses to capture it, then reference it in the substitution with $1 for the first group, $2 for the second, and so on. For example ^blog/(.*)$ → /posts/$1 captures everything after blog/ and places it after /posts/, so /blog/my-post becomes /posts/my-post. Groups from a RewriteCond use %1, %2 instead.
What is RewriteCond and how does it work with RewriteRule?
A RewriteCond is a condition that must pass before the RewriteRule immediately following it is applied. It typically tests a server variable such as %{HTTP_HOST}, %{REQUEST_URI} or %{HTTPS} against a pattern. Multiple RewriteCond lines stack (all must pass by default). For example, RewriteCond %{HTTPS} off before a rule means the rule only runs for non-HTTPS requests — the basis of a force-HTTPS redirect.
How to redirect all traffic to HTTPS using htaccess?
Use a condition that checks HTTPS is off, then redirect the whole path: RewriteEngine On, then RewriteCond %{HTTPS} off, then RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]. The pattern ^(.*)$ captures the entire path into $1, %{HTTP_HOST} keeps the same domain, and R=301,L makes it a permanent redirect and stops further processing.
What is the difference between RewriteRule and Redirect in htaccess?
Redirect (and RedirectMatch) are simpler directives from mod_alias that map one URL or prefix to another with no conditions and limited pattern support. RewriteRule is part of mod_rewrite and is far more powerful: it supports full regular expressions, capture groups, flags, and RewriteCond conditions. Use Redirect for straightforward one-to-one moves and RewriteRule when you need pattern matching, conditions, or query-string handling.

Related Tools