.htaccess to Nginx Converter - Convert Apache Rules
Turn common .htaccess directives into an Nginx configuration draft. Paste rules or choose a file, inspect the conversion notes, then copy or download the result. Your configuration stays in your browser.
- Free
- No input upload
- UTF-8, up to 1 MiB
Convert your configuration
Only UTF-8 is supported, with or without a UTF-8 BOM. UTF-16, NUL characters and inputs larger than 1,048,576 bytes (1 MiB) are rejected. Files are read locally.
Review the partial configuration before use. Unsupported directives need manual work; the result is not a complete server setup or a guarantee of equivalent behavior.
Ready. Nothing you paste or select is uploaded.
Nginx configuration draft
Merge this draft into the correct server context. Check paths, domain names, TLS and application handling; run nginx -t before reloading.
Conversion notes
Conversion runs on the browser's main thread. Large or complex inputs can briefly make this page unresponsive. There is no background worker or hard execution timeout.
How to convert .htaccess to Nginx
Add your Apache rules
Paste your .htaccess text or select a UTF-8 .htaccess, .conf or .txt file. Keep an unchanged backup of the original.
Convert and review
Choose whether to add a server wrapper and comments, then click Convert to Nginx. Read the line-by-line notes for anything that needs manual conversion.
Copy, test and reload
Copy the draft or download nginx.conf. Merge it into your server configuration, test with nginx -t, then reload only after checking the result.
Practical uses for this converter
Use a draft to plan an Apache-to-Nginx migration: identify simple redirects, directory index settings and rules that need an application-specific replacement.
Compare a small group of legacy URL rewrites with the equivalent Nginx structure before editing your server configuration.
Use the notes as a review checklist rather than assuming that omitted Apache directives are unnecessary. A skipped access-control rule can change who can read a resource.
For a WordPress move, start with the front-controller example below and separately configure PHP handling, protected paths and your actual document root.
What gets converted
| Apache input | Nginx approach | Review needed |
|---|---|---|
| RewriteRule | rewrite or redirect draft | Only a supported subset of patterns and flags; not every rewrite is equivalent. |
| RewriteCond | Single if, or flag variables for AND/OR groups | Supports mixed file tests. Ambiguous condition backreferences are not converted. |
| Front controllers | try_files for index.php, PATH_INFO and query-style routes | CodeIgniter needs PHP PATH_INFO handling; query routes preserve the path without a leading slash. |
| Redirect | Redirect rule | Check status codes, path matching and query strings. |
| DirectoryIndex | index directive | Confirm the files exist in the configured root. |
| ErrorDocument | error_page draft | Check local URI handling and response status. |
| Require, Files and FilesMatch | allow, deny and location blocks | Check scope, rule ordering and legacy access-control combinations. |
| Header | add_header | Always, replacement and inheritance behavior differ; unset needs manual handling. |
| ExpiresByType | Extension-based location with expires | The extension mapping only approximates MIME-type matching. |
| Options -Indexes | autoindex off | Check which directory should have listings disabled. |
| AddDefault | charset | Confirm the intended response character encoding. |
| AddType | types | Merge mappings carefully; Nginx MIME-type inheritance differs. |
| Other directives | Conversion note when unsupported | Do not silently discard authentication, access rules or module-specific behavior. |
Why Nginx has no .htaccess file
Nginx does not read per-directory .htaccess files. Its routing and access rules belong in the central configuration, usually inside a server block and its location blocks. Moving a .htaccess file into your document root will not activate those rules.
The optional server wrapper is a starting container, not a complete hosting configuration. Set your real listen, server_name and root, and configure TLS or application upstreams separately. Do not nest a generated server block inside an existing one.
After editing the actual configuration, run nginx -t to check syntax and referenced files. Reload Nginx only when the check succeeds, using your system's service command or nginx -s reload. Also test real requests: a syntax check does not prove that routing or access control is correct.
Apache and Nginx examples
These are hand-written migration examples, not a promise that every equivalent Apache input is automatically recognized. Replace example.com and merge each snippet into the right context.
WordPress front controller
A typical Apache setup sends requests for nonexistent files and directories to index.php.
Before - Apache .htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
After - inside an Nginx server block
location / {
try_files $uri $uri/ /index.php?$args;
}
Configure a separate, secure PHP handler and the correct document root. This snippet does not configure PHP-FPM, multisite, caching or security restrictions.
Redirect HTTP to HTTPS
Before - Apache .htaccess
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://example.com%{REQUEST_URI} [R=301,L]
After - dedicated Nginx HTTP server block
server {
listen 80;
server_name example.com www.example.com;
return 301 https://example.com$request_uri;
}
The HTTPS destination still needs its own TLS-enabled server block and certificate. Behind a proxy, check where TLS terminates before adding scheme-based redirects.
Redirect www to the preferred hostname
Before - Apache .htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^ https://example.com%{REQUEST_URI} [R=301,L]
After - Nginx hostname redirect
server {
listen 80;
server_name www.example.com;
return 301 https://example.com$request_uri;
}
This block handles HTTP only. Redirecting requests received at https://www.example.com also requires a TLS listener and a certificate valid for www.example.com.
Conversion limitations and safety checks
Apache per-directory rewrites match a path relative to the directory, often without a leading slash. Nginx server rewrites and location matching use different contexts. Rules copied from a nested .htaccess need their path prefix and document root checked manually.
Regular expressions, escaping, backreferences, query strings and rewrite flags can behave differently. The converter does not execute your patterns or simulate HTTP requests. A pattern that looks familiar is not proof of equivalent routing.
Multiple RewriteCond lines are converted using flag variables: consecutive OR conditions form a group, and groups are joined with AND, including the RewriteRule path pattern. A final OR flag is ignored. Single simple conditions use a compact if. Mixed file tests are supported; aliases and filesystem paths still need review.
Condition backreferences such as %1 are converted only from the last capturing condition of an AND-only chain. OR-group backreferences and other ambiguous captures are not converted. Rule backreferences such as $1 use named captures where condition regexes could overwrite Nginx's numbered captures.
CodeIgniter-style index.php/$1 routes use try_files with PATH_INFO. The PHP location needs fastcgi_split_path_info ^(.+\.php)(/.+)$; and fastcgi_param PATH_INFO $fastcgi_path_info;. Query-style index.php?url=$1 routes use a named location to preserve the path without its leading slash.
Nginx's often-cited "if is evil" warning concerns unsafe uses of the rewrite module's if inside location contexts. It does not mean all uses of if are forbidden. Prefer a structure you can reason about, and inspect generated conditionals instead of treating them as a universal Apache translation.
Authentication, module-specific sections, access controls and complex rewrite chains can require manual work. A skipped rule is not automatically safe to remove. Review every note, run nginx -t, and test redirects, query strings, missing files and protected resources in a staging environment before changing a live service.
Input is limited to 1,048,576 UTF-8 bytes. The main-thread parser can still pause the interface on complex input; there is no execution-time guarantee. The visible notes list shows at most 500 entries and shortens long entries; the notes download includes the full list.
.htaccess to Nginx FAQ
Can I use .htaccess directly with Nginx?
No. Move the relevant behavior into Nginx's central server and location configuration, test it and reload Nginx. Leaving .htaccess in the document root does not make Nginx apply it.
Is the output a complete, production-ready configuration?
No. It is a partial draft. Review the notes and configure domains, document roots, TLS, application handlers and security rules yourself. Even the optional server wrapper needs review.
Are my rules or files uploaded?
No. Input, filenames and generated output stay in browser memory. The app does not save input in browser storage or put it in page URLs. Loading the website still makes ordinary requests for page assets.
Which file formats and sizes are accepted?
Choose .htaccess, .conf or .txt files encoded as UTF-8, with or without a UTF-8 BOM. Both pasted input and files have a 1,048,576-byte limit. UTF-16, invalid UTF-8 files and NUL-containing input are rejected.
Why are some rules marked for manual review?
AND/OR condition chains are supported, but ambiguous condition captures, unsupported flags and module-specific behavior cannot safely be guessed. Apache and Nginx also differ in per-directory processing and PHP routing. Inspect each note and implement any omitted behavior in the appropriate Nginx context.
How do I test the converted configuration?
Merge the draft into a test configuration, then run nginx -t. After a successful check, reload the test server and request representative URLs. Verify status codes, Location headers, query strings and access restrictions; syntax validation alone is not enough.
Related tools
Regex Tester helps explore patterns on sample paths; its regex behavior is not a substitute for testing Apache or Nginx.
JSON to TypeScript generates declaration drafts from JSON samples when you are also migrating application code.
HTML Minifier reduces HTML markup after you have checked that your migrated site serves the right pages.