Developer and Text Tools

How to Test .htaccess and Nginx Rewrite Rules Before You Deploy

Stop redirect loops before they go live: paste mod_rewrite or nginx rules and a list of URLs, and see the status, target and a trace for every request.

Saizul Amin
Saizul Amin19 Nov 2026 · 5 min read
How to Test .htaccess and Nginx Rewrite Rules Before You Deploy

How to Test .htaccess and Nginx Rewrite Rules Before You Deploy

Few configuration lines cause as much trouble per character as rewrite rules. A site migration, an HTTPS switch or a new front controller usually means a handful of RewriteRule or rewrite lines, and a single mistake can create a redirect loop, lose the query string or send search engines a chain of 302s instead of one clean 301. The usual way to find out is to deploy, reload, read the error log and try again. This guide shows a faster loop with the free Apache and Nginx Rewrite Rule Tester, which simulates the server in your browser.

Why rewrite rules are hard to reason about

Apache's mod_rewrite reads like a list, but it does not behave like one. A RewriteCond belongs only to the RewriteRule directly below it. Conditions are joined with AND unless you add [OR]. Back-references come in two kinds: $1 from the rule's own pattern and %1 from the last matching condition. In an .htaccess file the pattern never sees the leading slash or the folder name, and after any internal rewrite Apache runs the whole file again with the new URL, which is why a catch-all rule to index.php can match itself forever.

Nginx is different again. It first runs rewrite directives at server level, then chooses one location block by a fixed order of exact matches, prefixes and regular expressions, runs that block's directives, and repeats the location search if a rewrite used the last flag or changed the URI. A rule that looks right on its own can simply never run because another location wins.

Step 1: choose the server and the context

Pick Apache or nginx. For Apache, say whether the rules live in an .htaccess file or in the virtual host configuration, and which folder the .htaccess sits in. This one choice changes what the pattern sees and whether the rules loop, so it is worth getting right.

Step 2: paste the rules

Paste the file as it is. Comments and unrelated directives such as Options or ErrorDocument are ignored. Syntax problems, like a RewriteRule without a substitution or a missing semicolon in nginx, are reported with their line, and unsupported directives get a warning rather than being silently skipped.

Step 3: describe the server around the rules

Many rules depend on the file system. The classic front-controller pattern serves a file if it exists and otherwise hands the request to index.php. Under Request and file system you list the paths that exist, for example /index.php, /style.css and /images, and -f, -d and try_files then answer as your server would. The same panel sets the User-Agent, Referer, cookie, method and client IP for rules that look at them.

Step 4: list the URLs and what you expect

Type one URL per line. Paths without a host use the default host you set. To turn the list into a regression test, add an arrow and the result you expect:

http://www.example.com/shop?x=1 -> 301 https://example.com/shop?x=1

Every line with an expectation is marked PASS or FAIL, and a counter shows how many passed. Keep this list in the saved project and run it again after every change; it is the cheapest insurance you can get for a migration.

Step 5: read the trace

Tap a URL to open its trace. Each directive the server considered appears in order with what happened: the subject string the pattern was tested against, whether it matched, the value of each condition's test string, the captured groups and the URL after the substitution. When .htaccess context causes another pass, a divider shows the URL that went round again. For nginx you see which locations were tested and which one won.

This is where most bugs become obvious. A condition testing %{HTTP_HOST} against ^www\. that never matches because the host has a port, a QSA flag that duplicates parameters, or a regex location that captures a static file before the intended prefix all show up in one or two lines.

Common fixes the trace points to

  • A loop in .htaccess: add conditions that skip existing files and folders, or use the END flag so the second pass stops.
  • Two hops instead of one for HTTPS and www: combine the conditions with [OR] and capture the bare host in the last condition so a single redirect handles both.
  • Lost query strings: Apache drops the original query when the substitution has its own unless you add QSA; nginx appends the original arguments unless the replacement ends with a question mark.
  • An nginx rewrite that never runs: check whether a regex location or an exact match takes the request first, or move the rewrite to server level.

What the simulator does not do

It does not run RewriteMap programs, proxy requests, evaluate Directory sections, or load included nginx files and other modules. Patterns run on JavaScript regular expressions, which match PCRE for normal rules; possessive and atomic groups are reported instead of guessed. Treat a clean result as strong evidence, then confirm the final rules on a staging host with a few curl requests.

Keep the work

Save the project to keep the rules, the URL list and the file system together, export it as JSON for a colleague, download the rules file, or print the results table as a PDF for the change ticket.

Completely freeNo cost, no sign-up
Files stay privateEverything runs in your browser
Easy in your languageAvailable in many languages