Skip to content

.htaccess to Nginx Converter

Paste an .htaccess file and get the Nginx equivalent: rewrite rules, redirects, HTTPS and www rules, access rules, headers and caching.

Runs in your browser

Examples:

Leave empty for the site’s root (or the folder named by RewriteBase). For a file in a subfolder, enter it, such as /blog/.

Nginx rules

How to use the converter

  1. Paste the contents of your .htaccess file, or load an example. If the file is in a subfolder rather than the site’s root, enter that folder.
  2. Read the converted rules, the notes, and the list of lines that need converting by hand. The converter never guesses: if a line has no safe Nginx equivalent, it says so.
  3. Paste the rules inside your site’s server { } block, run sudo nginx -t, and reload with sudo systemctl reload nginx. Then test the URLs that matter, especially redirects.

The conversion runs in your browser. Your .htaccess file is not sent to Cloudhim.

Why Nginx doesn’t read .htaccess

Apache checks every folder on the way to a file for an .htaccess file, on every request. Nginx reads its configuration once, at start-up, which is part of why it’s fast. So the rules have to move into the server configuration, and Nginx needs a reload (not a restart) whenever they change.

How the main rules translate

  • Front controller (WordPress, Laravel and most PHP frameworks): the “if the file doesn’t exist, send the request to index.php” rules become one line, try_files $uri $uri/ /index.php?$query_string;.
  • RewriteRule with [R=301] becomes rewrite … permanent;, and one without R becomes an internal rewrite. Patterns get a leading slash, because Nginx matches the full path while .htaccess rules see it without the folder.
  • HTTPS and www redirects become an if on $scheme or $host with a return 301. In Nginx the cleaner form is a separate server block per name; the Nginx Config Generator writes those for you.
  • Redirect and RedirectMatch become rewrite rules. Apache’s Redirect also moves everything below the old path, which the conversion keeps.
  • Access rules (Require all denied, Deny from all, <FilesMatch>) become deny all; in a matching location. Password protection becomes auth_basic, and Nginx reads the same .htpasswd file.
  • Headers, expiry and compression become add_header, expires and gzip.
  • PHP settings (php_value) can’t live in Nginx. They’re listed for your PHP-FPM pool file instead.

What needs a human

Nginx’s if takes a single test, so rules with several RewriteCond lines, including [OR] groups and %1 back-references, are converted with one flag per condition and a final check, the usual Nginx way of combining conditions. A few things still have no safe Nginx form: RewriteMap, conditions on variables Nginx doesn’t have, the [C], [S] and [P] flags, and <Directory> or <Limit> blocks. The converter lists each of those with its line number and the reason, so nothing is silently dropped.

After switching, check a few old URLs with the Redirect Checker to confirm each one still lands where it should.