Avoid htaccess to Nginx conversion mistakes by treating every directive as an item to classify, review, place in the right context, and validate before reload.
Apache and Nginx do not load rules in the same way. An .htaccess file is discovered through directories and can be affected by AllowOverride, while Nginx uses a centralized configuration and selects server and location contexts before rewrite processing. Copying an Apache rule into the nearest-looking Nginx block can therefore change its match, its condition, or its effect on the request.

Why the same rule can change meaning
The largest source of avoidable errors is assuming that matching text is identical. In a document-root .htaccess, Apache normally removes the directory prefix before a RewriteRule sees the path, so its pattern often starts with a caret and no slash. Nginx rewrite patterns see a URI beginning with a slash. The Apache mod_rewrite introduction describes the rewrite environment; the application’s real request path still has to guide the Nginx equivalent.
- Different matching input: confirm whether the source pattern is relative to a document root, a nested directory, an Alias, or a particular location.
- Different configuration scope: a rule that once applied to a directory may need a specific server or location block after migration.
- Different condition behavior: Apache conditions can inspect HTTPS state, host names, files, directories, query strings, headers, and captured groups, and their evaluation order matters.
- Different processing consequences: escaping, query handling, rewrite-loop behavior, and access effects can differ even when two regular expressions look alike.
Treat a converted line as a proposal for review, not proof of equivalence. Keep the original .htaccess and the final Nginx configuration in version control or an equally traceable change process.
Separate supported mappings from manual work
The htaccess to Nginx Converter is designed as an inventory assistant for the first pass of a migration. Paste a focused document-root .htaccess excerpt, and it emits only its narrow supported subset while reporting conditional, unfamiliar, or ambiguous material with the original line number. Processing remains in the browser, and the pasted input is not sent to Lizely.
The supported rewrite form contains an Apache RewriteRule pattern, a substitution, and a bracketed flag list. Its automatic flag set is limited to L, R, R=301, and R=302. A permanent redirect becomes the Nginx permanent flag, a temporary redirect becomes redirect, and an internal last rule becomes last. The three simple non-rewrite mappings are equally narrow:
| Apache input | Automatic result | Why it still needs review |
|---|---|---|
| Options -Indexes | autoindex off | Confirm the block that controls directory listings. |
| ErrorDocument 404 with a local path | error_page 404 with the same path | Only local 404 handling is supported; confirm the error context. |
| Header set X-Robots-Tag with a quoted value | An add_header line carrying that value | Conditional headers and other forms remain manual. |
| RewriteRule with a bracketed list using L, R, R=301, or R=302 | A rewrite line; R=301 becomes permanent, R=302 becomes redirect, and L becomes last | Verify the pattern, target, leading-slash scope, and directive context. |
RewriteEngine On is ignored. Other status codes, external error documents, conditional headers, environment variables, and directive containers require manual migration. The output is a fragment, not a complete nginx.conf: it does not create http, server, or location blocks, select a port, set server_name, configure TLS, locate a document root, preserve PHP routing, forward a proxy, or define logs.
For the 404 mapping, use Nginx’s error_page documentation to confirm the destination and context. For every emitted line, verify placement against the official Nginx directive documentation and the actual application architecture.
Audit and convert a focused excerpt
- Freeze and classify the source. Keep the original file unchanged. Identify whether the excerpt belongs to a document root, nested directory, Alias, or location-specific setup. The converter’s leading-slash treatment for a supported root-context pattern is a documented scope assumption, not a universal rule for nested files or aliased routes.
- Paste one focused excerpt. Use the converter for the supported document-root subset and check the converted count plus every line-numbered warning. The count does not prove that unconverted rules are unnecessary; each one still needs a resolution.
- Compare every output line with its source. Confirm the pattern, substitution, flags, directive context, and intended request behavior. Use the htaccess to nginx rules, limits, and warnings cheat sheet as a side review aid, but resolve each warning manually against Apache and Nginx documentation.
- Resolve unsupported rules without stripping their safeguards. RewriteCond lines are never translated automatically, and a RewriteRule following a condition is withheld rather than emitted as an unconditional redirect. Unknown flags such as QSA, END, F, G, B, or NC stop automatic conversion for that rule. Do not remove a condition or substitute a plausible flag just to make the output look complete.
- Handle the no-substitution case explicitly. A single dash as the rewrite target is withheld. It can combine with flags that alter access or processing without changing the URI, and a literal dash is not a safe Nginx replacement. Rebuild that behavior manually from the intended access and processing outcome.
- Assemble the fragment in context. Put each reviewed line in the correct server or location block in a version-controlled Nginx file. Preserve the rest of the working configuration, including application routing, proxying, TLS, roots, and logging. A line can be syntactically valid yet wrong for its location.
- Back up and validate the whole configuration. Back up the active configuration, keep an open recovery session, and run nginx -t against the complete assembled configuration before any reload. The tool cannot execute nginx -t, inspect installed modules, discover include order, or access the server.
- Test representative traffic. On staging or in a reversible maintenance window, request the old and new paths, query strings, alternate hosts, and HTTPS behavior. Check the expected status and Location header rather than trusting the browser address bar. Also test the local 404 page, directory-listing behavior, and X-Robots-Tag header when those directives were converted.
- Use temporary redirects first when practical. Permanent redirects can be cached by browsers and intermediaries, so confirm them carefully before switching from temporary behavior in a controlled environment. Reload only after validation and representative tests pass, and retain the backup for rollback.
Recognize the boundaries of automated conversion
The most dangerous mistake is treating an unsupported rule as if it were converted. The converter deliberately reports several cases rather than guessing:
- Conditions: RewriteCond is never translated automatically because variables, captures, evaluation order, and deployment context can change the result. The dependent rule is also withheld so that a condition does not disappear from an unconditional redirect.
- Unknown flags: QSA, END, F, G, B, and NC are outside the automatic set. Their details cannot be erased safely during a narrow conversion, so the affected rule requires manual work.
- No-substitution targets: the single-dash target is not translated to a literal Nginx dash. It is retained as a warning because it often works with flags that change access or processing.
- Path assumptions: inserting a leading slash can be appropriate for the supported document-root pattern, but it is not a blanket repair for nested .htaccess files, Alias mappings, or location-specific Nginx blocks.
- Context errors: generated syntax does not establish that a directive belongs in the selected block or that it preserves the application’s intended behavior.
These boundaries are useful controls, not cosmetic warnings. Resolve them in the source design or the assembled Nginx configuration, then validate the result as a whole.
Verify behavior instead of trusting syntax
A successful nginx -t shows that Nginx accepts the assembled configuration; it does not prove that a redirect has the right destination, that a rewrite avoids a loop, or that the application still reaches its front controller. Test behavior at the level users and crawlers will encounter.
- Request every important legacy URL and verify its status code, destination path, query handling, and response headers.
- Test the intended host and scheme separately so that an HTTPS or host condition is not accidentally broadened.
- For a local 404, confirm that the custom document is used for the intended status and that unrelated statuses still follow the site’s design.
- For directory listing, confirm that browsing the target directory no longer produces the listing.
- For X-Robots-Tag, confirm the response contains the intended value in the tested context.
Keep the test set small enough to run consistently but broad enough to cover the changed routes. If a redirect loops, exposes an unintended route, or returns the wrong target, restore the previous configuration and investigate the source rule and its context before trying another reload.
Know when the migration needs engineering work
Simple redirects, internal last rewrites, directory-listing controls, local 404 documents, and a simple X-Robots-Tag header can form a reviewable first pass. A short file is not necessarily a simple file, however. If the source contains authentication, authorization, hotlink protection, proxy logic, CMS front-controller rules, or complex conditions, treat the migration as engineering work rather than bulk text replacement.
Use the converter to inventory and separate the supported subset, then maintain a manual migration record for every warning and unsupported directive. That record should name the original line, the intended behavior, the chosen Nginx context, the test request, and the observed result. The goal is not a complete-looking Nginx file; it is a configuration whose behavior can be explained, tested, and reversed.
Related reading: How to Compare Nginx Config Generator Approaches.