Crawling
.htaccess Tester
Trace how RewriteRule, RewriteCond and Redirect handle each URL before you put the rules on a live server.
- Runs in your browser
- Nothing uploaded
The tool
Paste your rules and the URLs to test. The simulation runs in your browser and touches no server.
Loading the tool…
Everything you enter is processed by JavaScript in your own browser. Nothing is uploaded to us or to anyone else, which you can confirm in your browser network tab.
What this tool checks
- Simulates RewriteEngine, RewriteBase, RewriteCond and RewriteRule in per-directory context, the way an .htaccess file at the document root is evaluated
- Supports $1 and %1 back-references, server variables such as %{HTTP_HOST} and %{HTTPS}, and the L, R, NC, QSA, QSD, NE, F, G, END and OR flags
- Simulates Redirect, RedirectPermanent, RedirectTemp and RedirectMatch from mod_alias
- Re-runs the rules after an internal rewrite, as Apache does, and reports rewrite loops
- Follows redirects through the same rules to find chains and redirect loops
- Warns about malformed or PCRE-only patterns, missing RewriteEngine, leading slashes in per-directory patterns, R without L and rules that can never be reached
- Generates redirect rules for HTTPS, www or non-www, domain moves, trailing slashes and lists of old and new paths
How to read the results
- Each URL shows its outcome: a redirect with its status and target, an internal rewrite to the path the server would serve, a 403 or 410, or no change.
- Open the steps under a result to see every rule and condition that was tested, in order, with the values compared.
- An Indeterminate note means a condition tested whether a file or folder exists. Set the file option to match your situation and test again.
- Fix everything in the warnings list marked in red before uploading: those rules will not behave as written.
About this tool
How Apache reads an .htaccess file
An .htaccess file applies its rules to requests for the directory it sits in. Rewrite rules in this per-directory context see the URL path relative to that directory, without the leading slash. That is why RewriteRule ^about$ … matches /about in a root .htaccess, while RewriteRule ^/about$ … never matches. This tester assumes the file is in the document root.
Apache works through the rules from top to bottom. Each RewriteRule has a pattern tested against the path and, optionally, one or more RewriteCond lines directly above it. All the conditions must pass, unless they are joined with [OR]. When a rule matches, its substitution replaces the URL.
Internal rewrites and redirects
A substitution without the R flag is an internal rewrite: the visitor’s address bar does not change, but the server serves a different file. In per-directory context Apache then runs the rules again on the new URL, and keeps going until nothing changes. A rule like RewriteRule ^(.*)$ /index.php [L] without a condition that stops it on the second pass is a classic cause of the “too many internal redirects” error. The END flag stops that extra pass entirely.
With the R flag, Apache sends the browser to the new URL instead. Use R=301 for permanent moves. A plain R sends a 302, which tells search engines the old URL is still the one to keep. Always add L as well, otherwise Apache carries on processing later rules before redirecting.
RewriteEngine On
# Send http and www to https://example.com, in one hop
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L,NE]
Query strings
The pattern of a RewriteRule never sees the query string. Test it with RewriteCond %{QUERY_STRING}. If the substitution contains a ?, the new query replaces the old one unless you add QSA to append the original. QSD discards it. On a redirect without either, Apache keeps the original query.
Back-references
$1 to $9 refer to groups captured by the rule pattern. %1 to %9 refer to groups captured by the last condition that matched. The www redirect below uses the host name captured by its condition.
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L]
Redirect chains and loops
Every extra redirect hop costs a round trip, and search engines follow only a limited number of them. If one rule moves HTTP to HTTPS and another then moves www to non-www, many URLs take two hops. Combine them so every old URL reaches its final address directly. The tester follows each redirect through your rules and reports chains and loops.
Rules for a migration
Map every old URL to the most relevant new URL with a 301, rather than sending everything to the home page, which search engines tend to treat as a soft 404. Keep the redirects in place for at least a year. The generator tab writes the common patterns. Test the result here, then on a staging server, before going live.
Limits and honest caveats
- This is a simulation in JavaScript, not Apache. It covers the directives and flags listed above. Others, including RewriteMap, the S, C, P, PT, E and CO flags, and containers such as <If> and <Files>, are reported but not simulated.
- Patterns run as JavaScript regular expressions. They match PCRE for the common syntax, but possessive quantifiers, atomic groups and recursion are not supported and are flagged.
- File and folder tests such as !-f cannot see your server, so you choose whether the file exists.
- Server configuration outside .htaccess, such as virtual host rules, AllowOverride and other modules, can change the real result. Test on a staging server before going live.
What people use it for
- Checking HTTPS and www redirects before switching a site to HTTPS
- Tracing why a URL ends in a redirect loop or a 500 "too many internal redirects" error
- Writing and testing 301 redirects for a list of URLs changed in a redesign
- Understanding what a WordPress or framework rewrite block does to a given request
- Reviewing a client's .htaccess for risky or unreachable rules
Documentation and references
Related tools
Questions
Questions about this tool
The things clients actually want to know — costs, timelines, ownership and what happens after launch.
No. It simulates them in your browser. Nothing is uploaded or executed on a server, which also means server configuration outside the file is not taken into account.
In an .htaccess file the leading slash is removed before matching, so write ^about rather than ^/about.
Use 301 for a permanent move, such as a migration or a changed URL. Use 302 only when the original URL will come back.
A condition checks whether a file or folder exists on your server, which the tester cannot see. Choose the file option that matches and run the test again.
In this simulation mod_rewrite runs first and Redirect lines apply when no rewrite changed the URL. Mixing the two modules for the same URLs is best avoided.
Documentation last reviewed: by the Best Web Developer engineering team.
Free strategy session
Let’s build something worth finding.
Tell us where you want the business to be in twelve months. We will come back with a costed plan, a realistic timeline, and the numbers we expect to move — no obligation, no jargon.
- 30-minute call, no pitch deck
- Fixed-price proposal in 48 hours
- You own everything we build
Talk to a developer
Not a sales team
- Response time
- Within 1 business hour
- Where we work
- UK, USA & the Gulf
- Contracts
- No lock-in, monthly rolling
- Working since
- 2023