nginx Rewrite Rule Tester

nginx rewrite rules are powerful but unforgiving — a missing flag, a wrong regex anchor, or a misunderstood location match order and your request lands somewhere unexpected. This tester takes a snippet of nginx config and a request URL, then simulates which location block matches and what the URL rewrites to.

How to use the nginx Rewrite Rule Tester

Paste the nginx location / rewrite directives (you don't need the server block). Type a request path. The tool shows which location block wins, why, and what the final URL becomes after any rewrites.

About nginx Rewrite Rule Tester

nginx location matching uses these priority rules (highest to lowest):

  1. location = /exact — exact match, highest priority.
  2. location ^~ /prefix — prefix match with "no regex" flag.
  3. location ~ regex or location ~* regex — regex match (case-sensitive / insensitive), evaluated in config order.
  4. location /prefix — longest matching prefix, lowest priority.

Once nginx picks a location, it processes any rewrite directives inside. Flags control what happens after:

  • last — rewrite and re-process location matching with the new URL.
  • break — rewrite but don't restart matching (continue in current location).
  • redirect — return 302 to the client.
  • permanent — return 301 to the client.

try_files is a different mechanism: try each path in order, fall back to the last argument if none match.

Common use cases

  • Debugging 404s — figure out why your rewrite isn't catching requests.
  • Verifying location order — when you have multiple regex locations, see which wins for a given URL.
  • Learning nginx — see exactly how each rule processes.
  • Pre-deploy verification — test before pushing config to production.