Skip to content
migration.tools
.htaccess to nginx

.htaccess to nginx converter

Moving from Apache to nginx means .htaccess files stop working — nginx doesn't read them. Paste yours and get equivalent server-block directives, with every line that has no safe translation marked TODO instead of quietly disappearing.

.htaccess

nginx config

The result appears here as soon as there is input.

Processed on this device. Nothing you paste or drop is uploaded.

How to use it

  1. 1Paste your .htaccess file.
  2. 2Copy the output into the server { } block of your site's nginx config.
  3. 3Run nginx -t to validate it, then reload nginx and test the URLs that matter.

What is translated

RewriteRule and RewriteCond pairs become rewrite, return and if directives. Common patterns are recognised and written idiomatically: the “not a file, not a directory → index.php” front controller becomes try_files, and HTTPS and www canonicalisation become single return 301 lines.

Redirect and RedirectMatch, ErrorDocument, DirectoryIndex, Options -Indexes, Header set, ExpiresByType, mod_deflate, FilesMatch blocks, Deny/Allow/Require rules and basic auth all have direct nginx counterparts.

nginx's if can't combine conditions with AND. When a rule has several RewriteCond lines, the converter uses the standard workaround: each condition appends to a variable, and the rule fires only when all of them matched.

What needs a person

php_value and php_flag settings belong in php.ini or the PHP-FPM pool, not nginx. %N back-references to RewriteCond captures, SetEnvIf and handler directives have no direct equivalent. Each is left in the output as a TODO comment with the reason.

Because .htaccess is evaluated per directory and nginx config per server, rules copied from a subdirectory need their paths prefixed. The converter honours RewriteBase when it is set.

Questions

Where do I put the converted rules?

Inside the server { } block for the site, usually in /etc/nginx/sites-available/your-site or /etc/nginx/conf.d/your-site.conf. Location blocks produced by the converter can sit alongside your existing ones.

Will my WordPress permalinks work?

Yes. The standard WordPress rewrite block converts to location / { try_files $uri $uri/ /index.php?$args; }, which is the configuration WordPress documents for nginx.

Guides that use this tool