How to convert .htaccess rewrite rules to Nginx

The converter reads the rewrite rules of an .htaccess file and prints the Nginx lines that match them: RewriteRule becomes rewrite, RewriteCond becomes the if blocks that guard it. The work happens in the page, and the rules are never uploaded.

Only rewrite rules are translated. Everything else — RewriteBase, Redirect, Header, Options and similar Apache directives — is listed in a comment at the end of the result instead of being copied over, so you can see what still needs a decision.

  1. Paste the rewrite rules from your .htaccess file into the box.
  2. Press “.htaccess to Nginx” to generate the result.
  3. Read the comment block at the end: it names the directives and flags that were not converted.
  4. Paste the output into the server block and run nginx -t before you reload.
  5. Press Clear to reset the form before the next run.

What is translated, what is reported, and how to verify the result

What the converter translates

RewriteRule lines become rewrite statements with the same pattern: [L] becomes last, [R=301] permanent, [R=302] and [R] redirect, and [NC] is written as an inline (?i) so the match stays case-insensitive. [E=NAME:value] becomes set $NAME value; — the form nginx accepts.

RewriteCond lines become if blocks that assign a $rule_N variable, and the rule they guard runs inside if ($rule_N = "..."). File tests map as well: -f becomes !-f when negated, -d stays -d, and -s becomes -e.

What is reported instead of converted

Apache directives without an Nginx equivalent are not dropped silently: the result ends with a comment listing them, together with rewrite flags such as S= or T= that have no Nginx counterpart.

[F], [G] and [P] rules are not converted either, because an unqualified 403 or a proxied rewrite would behave differently in nginx. The tool prints the rule and the construct to add by hand. A condition it cannot read is marked #ignored, and the rule it guarded stays inactive until that condition is rewritten.

Limits and how to verify

Input is capped at 6,000 characters, so split large .htaccess files. The result is a starting point, not a finished configuration: quoting, location blocks and server context still depend on your setup.

Keep the generated block in a server block, run nginx -t, and test one redirect in a browser before the switch. The conversion runs locally in JavaScript, so the rules never leave the page and a run still works offline.

Recent tools: