Need to move a website from Apache to Nginx? This free htaccess to nginx converter turns your Apache .htaccess rules into Nginx configuration. Paste your code or upload a file, choose the output format, and review the result. Everything runs in your browser, so your configuration isn't uploaded or stored.
What Does the .htaccess to Nginx Converter Do?
Apache and Nginx handle server rules in different ways. Apache can read .htaccess files inside website folders, but Nginx doesn't support them. You must move those rules into the main Nginx server configuration.
This tool reads your Apache directives and creates matching or approximate Nginx rules where possible. It can handle several common tasks:
- URL rewrites and redirects: Convert RewriteRule, RewriteCond, Redirect, and 410 Gone rules.
- Front controllers: Recognize common WordPress and Laravel patterns and turn them into try_files directives.
- HTTPS and www redirects: Convert common rules for secure connections and preferred domain names.
- Error pages and headers: Map supported ErrorDocument and header directives to Nginx equivalents.
- Caching and compression: Convert supported Expires rules and gzip settings.
- Access control: Handle supported file and folder restrictions and Basic authentication rules.
- PHP settings: Process supported php_value and SetEnv lines.
You can choose between output containing just the converted rules or a full server block. The full block can include a server name, document root, and PHP-FPM settings. You can also keep the original Apache lines as comments for easier review.
How to Convert .htaccess to Nginx
You don't need to install software or create an account. Follow these steps to convert your Apache configuration:
- Open the converter: Go to the .htaccess to Nginx Converter on AllToolz4U.
- Add your Apache rules: Paste the contents of your .htaccess file into the input area, or upload the file.
- Set the folder path: If your rules belong to a subfolder, such as /blog/, use the folder option. This helps the converter account for the original rule location.
- Choose the output: Select rules-only output or a complete Nginx server block. Set the available options, such as keeping original lines as comments.
- Convert your rules: Start the conversion and wait for the generated Nginx configuration.
- Review the report: Open the Line by line tab to check rules that need manual changes or couldn't be converted.
- Copy and test: Copy the result into your Nginx configuration, then run nginx -t on your server before reloading it.
Keep a backup of your original .htaccess file. It's also a good idea to test the new configuration on a staging site before changing a live website.
How Are Apache Rewrite Rules Converted to Nginx?
The converter checks each Apache directive and maps supported patterns to Nginx directives. It doesn't simply replace Apache command names with Nginx command names. The two servers use different rule systems, so the conversion depends on the original conditions, flags, and request paths.
For example, a common WordPress front-controller rule uses RewriteRule and RewriteCond to send requests that don't match existing files or folders to index.php. Nginx can handle this pattern with try_files.
Apache .htaccess example:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Equivalent Nginx location example:
location / {
try_files $uri $uri/ /index.php?$args;
}
The try_files directive checks whether the requested file or directory exists. If neither exists, Nginx passes the request to index.php while preserving the query string. This is a common approach for WordPress and other PHP applications.
Here is another example of a permanent redirect:
Apache rule:
RedirectPermanent /old-page /new-page
Nginx equivalent:
location = /old-page {
return 301 /new-page;
}
These examples show common conversion patterns. Your actual output may differ depending on the source rules and selected options.
What Happens to Unsupported .htaccess Directives?
Not every Apache directive has a direct Nginx equivalent. Some depend on Apache modules or features that work differently in Nginx. A basic text converter could miss these differences, leaving you with an incomplete configuration.
This tool provides a Line by line report to show rules that were converted approximately or not converted. It also gives a reason for each reported issue instead of silently dropping the original line.
Some directives and patterns the converter doesn't handle include:
- SetEnvIf directives
- AddHandler directives
- Apache <If> blocks
- Digest authentication
- Rewrite flags such as [C], [S], and [N]
PHP settings and environment variables also need attention. For example, php_value and SetEnv don't work in Nginx in the same way they do in Apache. You may need to move these settings into PHP-FPM pool configuration or another suitable server configuration file.
Don't treat an approximate conversion as a confirmed equivalent. Read the report and decide how to handle each flagged directive before deployment.
Practical Tips for a Successful Apache to Nginx Migration
A converted configuration is a starting point. A few checks can save you from broken pages, redirect loops, and unexpected server behavior.
- Check the rule location: Apache .htaccess rules can apply to a specific directory. Use the folder option when converting rules from paths such as /blog/ or /shop/.
- Review redirect targets: Check every 301 and 302 redirect. A small path difference can send visitors to the wrong page.
- Watch rewrite conditions: AND and OR conditions can affect which requests match a rule. Review their logic instead of checking only the generated rewrite directive.
- Check query strings: Make sure redirects and rewrites preserve or remove query parameters as your application expects.
- Review PHP settings: Move unsupported PHP directives to the correct PHP-FPM configuration instead of placing them in an Nginx server block.
- Test the configuration: Run nginx -t to check its syntax. Then test important URLs, login pages, forms, images, and downloads.
- Keep a backup: Save your original Apache file and current Nginx configuration so you can roll back if needed.
Also, remember that Nginx doesn't use .htaccess files. Converted rules generally belong in the relevant server or location block, not in a new .htaccess file.
Who Should Use This .htaccess to Nginx Converter?
This tool is useful for developers and system administrators moving websites from Apache hosting to Nginx. It can also help freelancers and agencies who inherit an existing client website with a large collection of rewrite and redirect rules.
WordPress and Laravel site owners may find it useful when moving from shared Apache hosting to a VPS running Nginx. Instead of rewriting every rule from scratch, they can convert common patterns and review the output.
It's also a practical learning aid. If you're new to Nginx, comparing Apache directives with their generated equivalents can help you understand how URL rewriting, redirects, and front controllers work.
The converter is free, requires no sign-up, and processes your input entirely in your browser. Use it to prepare a first draft of your Nginx configuration, then review and test every important rule before putting your website live.