A safe htaccess to nginx conversion produces review-ready lines that match a narrow, auditable subset of Apache directives and returns explicit line-numbered warnings for everything it cannot translate — it never guesses. The htaccess to Nginx Converter follows that contract: paste a focused document-root .htaccess excerpt, receive only the RewriteRule flags and three non-rewrite mappings it explicitly supports, and act on every warning before any configuration is merged into nginx.conf. Output stays in the browser, no input is uploaded, and the fragment you receive is not a complete server block — placing directives in the correct Nginx context, running nginx -t and testing representative requests are steps you still own. That restraint is what makes the conversion safe to load: a silently written plausible but non-equivalent rule is more dangerous than an explicit warning, because a failed reload or redirect loop can take a public site offline. Treat every emitted line as something to verify against the official Apache and Nginx documentation before you back up, validate and reload.

What "safe" actually means when converting htaccess to nginx
Safety in this context is the opposite of cleverness. A converter that confidently rewrites every line it sees — including conditions, unknown flags, conditional headers, the Apache no-substitution dash, nested <If> containers and proxy logic — produces output that compiles but changes traffic in ways the operator never approved. The risk is not syntax; it is equivalence. Apache and Nginx use different request-processing models: .htaccess is discovered through directories and may be disabled by AllowOverride, while Nginx reads centralized configuration and chooses server and location contexts before rewrite processing. Even identical regular expressions can behave differently because the string being matched, escaping, query-string handling and loop behavior differ. A safe converter limits its own scope on purpose, refuses to translate anything whose meaning depends on context it cannot inspect, and marks that refusal with the original line number so a human can resolve it. The defining test is simple: if the tool emitted no line at all for a rule, did it tell you why?
The conversion contract: what is supported and what is not
The htaccess to Nginx Converter advertises an explicitly narrow contract rather than a universal translator. A supported RewriteRule must contain an Apache pattern, a substitution and a bracketed flag list. The automatic flag set is intentionally limited to L, R, R=301 and R=302. A permanent Apache redirect becomes the Nginx permanent flag, a temporary redirect becomes redirect, and an internal last rule becomes last. Patterns in a document-root .htaccess normally match a path after the directory prefix has been removed, so they commonly begin with a caret but no slash; Nginx rewrite patterns see a URI that begins with a slash, so the converter inserts that leading slash for the supported root-context pattern. This is a documented scope assumption, not a universal transformation for nested .htaccess files, Alias mappings or location-specific blocks.
Three non-rewrite mappings are supported: Options -Indexes becomes autoindex off, a local ErrorDocument 404 path becomes error_page 404 with the same path, and a quoted X-Robots-Tag Header set value becomes an add_header line. Other status codes, external error documents, conditional headers, environment variables, authentication directives and containers require manual migration. RewriteCond lines are never translated automatically because their variables, captures, evaluation order and deployment context can change meaning; when a RewriteRule follows a condition the tool suppresses the rule too, rather than emitting an unconditional redirect that could change traffic, create a loop or expose a route. The Apache no-substitution target represented by a single dash is also withheld because it often combines with flags that alter access or processing without changing the URI, and a literal dash is not a safe Nginx replacement.
| Apache token | Intended Nginx output | Tool behavior |
|---|---|---|
| R=301 | permanent | Emitted |
| R=302 or R | redirect | Emitted |
| L | last | Emitted |
| QSA, END, F, G, B, NC | — | Warning, no output for that rule |
| RewriteCond + dependent RewriteRule | — | Warning, rule suppressed |
| Substitution - (dash target) | — | Warning, no output |
| Options -Indexes | autoindex off; | Emitted |
| ErrorDocument 404 /local-404.html | error_page 404 /local-404.html; | Emitted |
| Header set X-Robots-Tag "noindex" | add_header X-Robots-Tag "noindex"; | Emitted |
Convert htaccess to nginx safely: a review-first workflow
The operating model is intentionally short. Three steps cover a focused excerpt; everything outside that excerpt stays in human hands.
- Paste a focused document-root .htaccess excerpt. Trim the file to the RewriteRule lines, the Options -Indexes line, the local ErrorDocument and the quoted X-Robots-Tag you intend to migrate. Do not paste authentication, proxy, CMS front-controller, hotlink protection or container blocks — the converter is not designed to translate those and they belong in manual work.
- Convert only the explicitly supported subset. Submit the excerpt to the htaccess to Nginx Converter and read every emitted line. Each line corresponds to a single directive the tool accepts, with a leading slash inserted on document-root rewrite patterns. Comments are preserved. Anything conditional, unfamiliar or syntactically ambiguous is reported with its original line number for manual review.
- Review, back up, merge and validate before reload. Resolve each line-numbered warning manually against the Apache mod_rewrite introduction and the relevant Nginx documentation. Place each reviewed line in the correct server or location block. Back up the active configuration, run nginx -t, test representative requests on staging, then reload.
Read every line-numbered warning before touching nginx.conf
The warning list is not noise; it is the audit trail. A warning tells you the converter saw a token whose Nginx equivalent cannot be written safely without inspecting your server, application, headers or condition chain. Treat each entry as a checklist item with three possible resolutions: confirm the rule is irrelevant in Nginx (for example, an Apache-only behavior) and remove it; rewrite the rule by hand from the Apache and Nginx docs; or preserve the rule as-is in Apache if a coexistence plan is in place. Unknown flags such as QSA, END, F, G, B and NC stop conversion for that rule because their details cannot be erased safely, and the converter does not emit a guessed replacement. The dash target produces a warning because a literal dash is not a safe Nginx substitution and the original rule often combined with flags that altered access or processing without changing the URI. When a RewriteCond precedes a RewriteRule the rule is suppressed as well, because writing an unconditional redirect that ignores the condition can change traffic, create a redirect loop or expose a route that the condition was meant to guard.
Stage, test and reload — the deployment discipline
Output is a fragment, not a complete nginx.conf. It does not create an http, server or location block, choose a listen port, set server_name, configure TLS, locate a document root, preserve PHP routing, forward a proxy or define logs. Place each reviewed line in the correct context according to the official Nginx directive documentation and the actual application architecture. The tool does not execute nginx -t, inspect installed modules, discover include order or access your server — a line can be syntactically valid yet wrong for its context. Back up the active configuration, keep an open recovery session, validate the entire assembled configuration and stage representative requests before reloading. A failed reload or redirect loop can make a public site unavailable. Permanent redirects deserve extra care because browsers and intermediaries may cache them; start with temporary redirects in a controlled environment when practical, then switch to permanent only after testing old paths, new paths, query strings, alternate hosts and HTTPS behavior, and confirm the response Location header rather than relying on the browser address bar alone.
When safe conversion is not enough: migrate manually
The converter is an inventory assistant for the supported subset, not a universal translator. If the source contains authentication, authorization, hotlink protection, proxy logic, CMS front-controller rules, conditional headers, environment variables or complex conditions, treat the migration as engineering work rather than bulk text replacement. Use the converter to paste one focused excerpt at a time, review the converted count against the input, resolve every warning, assemble the result in a version-controlled Nginx file and validate it on staging. For anything outside the explicit contract — including <If>, <ElseIf>, SetEnvIf, RewriteMap, ProxyPass equivalents, AuthType, Require and CMS-specific front controllers — read both the Apache and Nginx manuals line by line and plan the cutover with a reversible maintenance window, not a one-click reload.
For a deeper look, see Is a Meta Robots Generator Safe? Pre-Use Checks That Matter.
For a deeper look, see Nginx Config Generator on Windows: Paths and Testing.