SysAdmin Tools

Apache Rewrite Rule Tester

Test .htaccess mod_rewrite RewriteRule and RewriteCond patterns in your browser — see the rewritten URL, status, flags and a step-by-step trace.


Advertisement

Test Before Applying

Generated configuration is a starting point. Always:

  • Test in a non-production environment
  • Validate syntax before reloading services
  • Keep a backup of your working config
  • Adapt to your specific server setup

SysAdmin Tools provides this as a reference only and is not responsible for service interruptions.

This tool simulates Apache mod_rewrite behavior in the browser. For production, always test on your actual Apache server.
1. Test URL

Enter the URL you want to test

2. Rewrite Rules

Advertisement

Related: .htaccess Generator →

Advertisement

This Apache rewrite rule tester simulates mod_rewrite in your browser so you can check how a RewriteRule or RewriteCond behaves before deploying it. Paste a test URL and your .htaccess rules, hit Test, and see the rewritten URL, the HTTP status, the flags that fired, and a step-by-step trace of every rule evaluated.

Apache's mod_rewrite is famously hard to debug: a pattern that looks right can silently fail to match, loop, or redirect to the wrong place. This mod_rewrite tester parses RewriteEngine, RewriteRule and RewriteCond directives, supports common flags (R, L, NC, QSA, NE, P), evaluates backreferences ($1, %1), and shows you exactly which rule changed the URL. Quick-start templates cover 301 redirects, removing .php, forcing HTTPS, www/non-www and trailing-slash rules.

Because it runs entirely client-side, no request ever leaves your browser. It is a learning and debugging aid — always confirm behaviour on your real Apache server before relying on it in production.

How to Use the Apache Rewrite Tester

  1. 1

    Enter a test URL

    Type the URL you want to check, such as https://example.com/old-page. The path and query string are extracted and fed into the simulator as the incoming request.

  2. 2

    Add your rewrite rules

    Paste your RewriteEngine, RewriteCond and RewriteRule lines into the rules box, or load a quick template (301 redirect, remove .php, force HTTPS, www to non-www, remove trailing slash).

  3. 3

    Set server variables (optional)

    Open the advanced panel to set HTTP_HOST, the HTTPS on/off state, HTTP_USER_AGENT and QUERY_STRING so RewriteCond directives that test those variables evaluate correctly.

  4. 4

    Run the test

    Click Test Rewrite Rules. The result card shows whether a rule matched, the input and output URL, the status code and the active flags.

  5. 5

    Read the trace

    Review the step-by-step trace to see each rule evaluated, which pattern matched, and what each flag did — then adjust your rules and re-test.

Understanding mod_rewrite Rules

A mod_rewrite ruleset processes the requested URL path top to bottom. Each RewriteRule has a pattern (a regular expression matched against the path), a substitution (the replacement, or - for no change), and optional flags in square brackets. A rule can be preceded by one or more RewriteCond directives, which are extra conditions (often testing server variables like %{HTTPS} or %{HTTP_HOST}) that must all pass for the following rule to apply. Flags control what happens. [R=301] issues an external redirect with that status; [L] stops processing further rules; [NC] makes the pattern case-insensitive; [QSA] appends the original query string to the substitution; [NE] prevents escaping of special characters; and [P] proxies the request. Patterns capture groups that you reference in the substitution as $1, $2 (from the RewriteRule) and %1, %2 (from the last matching RewriteCond). This simulator applies those rules to the path you provide and reports the outcome. It is a close approximation for common redirect and rewrite scenarios, but real Apache has subtleties — per-directory context stripping the path prefix, repeated passes through the ruleset, interaction with other modules — that a browser cannot perfectly reproduce. Use it to understand and sanity-check rules, then verify on the server.
FieldDescription
RewriteEngineTurns rewriting on or off; rules are ignored unless RewriteEngine On is present.
RewriteRuleA pattern, a substitution and optional flags — the core rewrite/redirect instruction.
RewriteCondA condition tested before the following RewriteRule; all conditions must pass for the rule to run.
[R=301]Performs an external redirect with the given status (301 permanent, 302 temporary).
[L]Last rule — stops processing the remaining rules once this one matches.
[NC]No case — makes the pattern match case-insensitively.
[QSA]Query String Append — keeps the original query string on the rewritten URL.
$1 / %1Backreferences to captured groups from the RewriteRule ($) and the last RewriteCond (%).

Advertisement

Common Rewrite Testing Use Cases

Verify a 301 redirect before deploy

Confirm that an old URL redirects to the new one with the correct 301 status and no accidental loop, so SEO link equity is preserved and visitors are not bounced incorrectly.

Debug a rule that is not matching

Use the step-by-step trace to see why a RewriteRule pattern fails to match a path — a missing anchor, a wrong escape, or a RewriteCond that is quietly failing.

Check HTTPS and www canonicalisation

Test force-HTTPS and www/non-www rules against several URLs to ensure every variant lands on the single canonical form you intend.

Learn mod_rewrite safely

Experiment with patterns, flags and backreferences and watch the result instantly, without touching a live server or risking a site-wide redirect loop.

Apache Rewrite Rule Tester — Frequently Asked Questions

What is Apache mod_rewrite?
mod_rewrite is an Apache module that rewrites requested URLs on the fly using regular-expression rules. It powers pretty URLs, redirects, HTTPS and www canonicalisation, and front-controller routing for frameworks. Rules are usually written in a site's .htaccess file or the server/vhost config with RewriteEngine, RewriteCond and RewriteRule directives. It is extremely flexible but also a frequent source of hard-to-debug redirect issues.
How to test Apache rewrite rules online?
Use a client-side simulator like this one: enter the URL you want to test, paste your RewriteRule and RewriteCond lines, optionally set server variables such as HTTP_HOST and HTTPS, then run the test. The tool reports the rewritten URL, the HTTP status, the flags that fired, and a trace of each rule. Because real Apache behaviour can differ in complex cases, always confirm on your actual server afterwards.
What is the difference between 301 and 302 redirect in Apache?
A 301 is a permanent redirect: browsers and search engines cache it and pass link equity to the new URL, so use it when a page has moved for good. A 302 (or 307) is temporary: clients keep requesting the original URL and link equity is not transferred, suitable for short-lived redirects like maintenance pages or A/B tests. In mod_rewrite you set these with the flag [R=301] or [R=302] on a RewriteRule.
How to write a RewriteRule in .htaccess?
The syntax is RewriteRule PATTERN SUBSTITUTION [FLAGS]. For example RewriteRule ^old-page$ /new-page [R=301,L] matches the path "old-page" exactly and permanently redirects it to /new-page, stopping further processing. The pattern is a regex matched against the URL path (without the leading slash in per-directory/.htaccess context), the substitution is the target, and flags in brackets modify the behaviour. Add RewriteEngine On once at the top.
What does RewriteCond do in Apache?
RewriteCond defines a condition that must be true for the RewriteRule immediately following it to apply. It typically tests a server variable, e.g. RewriteCond %{HTTPS} off before a rule that redirects to HTTPS, or RewriteCond %{HTTP_HOST} ^www\. to match www hosts. Multiple RewriteCond lines stack with implicit AND (use the [OR] flag for OR). Captured groups from the last matching condition are available in the rule as %1, %2.
How to redirect www to non-www in Apache?
Use a condition on the host and a redirect rule, for example: RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] then RewriteRule ^(.*)$ https://%1/$1 [R=301,L]. The condition captures the domain without the www into %1, and the rule rebuilds the URL and issues a permanent redirect. Reverse the logic (match non-www, redirect to www) to force the www version instead. Test both directions to avoid loops.
How to force HTTPS in .htaccess?
Add: RewriteEngine On, then RewriteCond %{HTTPS} off, then RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]. The condition matches requests that arrived over plain HTTP and the rule redirects them to the same host and path over HTTPS with a permanent status. Behind some proxies/CDNs you may need to test %{HTTP:X-Forwarded-Proto} instead of %{HTTPS}. Always verify there is no redirect loop.
What are Apache RewriteRule flags?
Flags in square brackets modify a rule. Common ones: R[=code] external redirect (301/302); L last rule, stop processing; NC case-insensitive match; QSA append the original query string; NE do not escape special characters; P proxy the request; and F forbidden (403). You can combine them, e.g. [R=301,L,NC]. Choosing the right flags — especially L to prevent unintended further matching — is key to predictable rewriting.
How to remove .php extension with mod_rewrite?
A common approach: RewriteCond %{REQUEST_FILENAME}.php -f then RewriteRule ^(.*)$ $1.php [L], which internally serves /page.php when /page is requested. To also redirect visitors from the .php URL to the clean one, add a separate external redirect rule. Test both the internal rewrite and the external redirect so you get clean URLs without a loop between the two rules.
How to debug Apache rewrite rules?
On a server, enable the rewrite log (LogLevel rewrite:trace3 in Apache 2.4) and inspect which rules fire. Before touching the server, use a simulator like this tool to trace rule evaluation and spot pattern or flag mistakes. Common pitfalls are missing ^ or $ anchors, forgetting the [L] flag (causing further rules to run), case sensitivity (add [NC]), and RewriteCond variables that do not hold what you expect.
Is this simulator exactly the same as real Apache?
No — it is a close approximation for common redirect and rewrite patterns, designed for learning and quick debugging. It does not reproduce every nuance of Apache: per-directory path prefix stripping, repeated passes over the ruleset until the URL stabilises, interaction with other modules, or server-specific configuration. Treat the results as a guide and always validate your rules on the actual Apache server before deploying them to production.

Related Tools