.htaccess to Nginx Converter
Convert Apache .htaccess rewrite rules, redirects and headers into Nginx configuration.
.htaccess to Nginx Converter
Nginx does not read .htaccess files, so moving a site from Apache (most shared hosting) to Nginx means rewriting its rules by hand. This converter does the translation for you: RewriteRule and RewriteCond become rewrite, return and if blocks, Redirect and RedirectMatch become redirects, and ErrorDocument, DirectoryIndex, Options -Indexes, Header, Expires, access rules and Basic Auth get their Nginx equivalents. It recognises the common patterns, such as HTTPS and www redirects and the WordPress or Laravel front controller, and writes them the way an Nginx admin would. Anything it cannot convert stays as a comment, so nothing is lost silently.
How to use .htaccess to Nginx Converter
- Paste the contents of your .htaccess file, or click Try an example.
- The Nginx configuration appears as you type.
- Read the notes at the end and check any lines marked "Not converted".
- Paste the result inside your site's
server { }block, runnginx -tand reload Nginx.
When it comes in handy
- Moving a WordPress, Laravel or PHP site from Apache hosting to an Nginx server or VPS.
- Adding a site's old redirects to an Nginx reverse proxy.
- Learning how an Apache rule is written in Nginx.
Frequently asked questions
- Why does Nginx not use .htaccess?
- Apache checks for .htaccess files in every folder on every request, which is slow. Nginx reads its configuration once at start-up, so all rules go into the server block instead.
- Is the conversion always exact?
- Common rules convert cleanly, but Apache and Nginx handle some edge cases differently (for example back-references from RewriteCond and mixed [OR] conditions). The converter flags these in the notes. Always test with
nginx -tand try your important URLs after reloading. - Where does the WordPress rule go?
- The WordPress and Laravel "send everything to index.php" rule becomes a
location / { try_files $uri $uri/ /index.php?$args; }block, added at the end of the output. You still need the usuallocation ~ \.php$block that passes PHP to PHP-FPM. - Is my configuration uploaded?
- No. The conversion runs in your browser.