Skip to main content

Apache .htaccess to NGINX converter

Free online tool to convert Apache .htaccess configuration to NGINX server block format. Supports RewriteRule, RewriteCond, Redirect directives and more.

Want NGINX Plus features at a fraction of the cost? Meet NGINX Extras — HTTP/3, Brotli, ModSecurity, PageSpeed & 100+ modules! Learn More →
Supports RewriteRule, RewriteCond, Redirect, RedirectMatch, ErrorDocument, and more.

How to Convert Apache .htaccess to NGINX

Migrating from Apache to NGINX? Our free converter tool automatically translates your .htaccess rules into equivalent NGINX configuration directives. Simply paste your Apache configuration above and get instant results.

Supported Apache Directives

  • RewriteRule → NGINX rewrite
  • RewriteCond → NGINX if conditions
  • Redirect → NGINX return
  • RedirectMatch → NGINX rewrite
  • RedirectPermanent → NGINX return 301
  • ErrorDocument → NGINX error_page
  • DirectoryIndex → NGINX index
  • Header → NGINX add_header

Common Conversion Examples

Force HTTPS Redirect

Apache (.htaccess):

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

NGINX:

if ($scheme = "http") {
    return 301 https://$host$request_uri;
}

301 Redirect Old URL to New URL

Apache (.htaccess):

Redirect 301 /old-page.html /new-page/

NGINX:

location = /old-page.html {
    return 301 /new-page/;
}

Remove .html Extension

Apache (.htaccess):

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html [L]

NGINX:

try_files $uri $uri.html $uri/ =404;

Frequently Asked Questions

Can NGINX read .htaccess files?

No, NGINX does not support .htaccess files. Unlike Apache, NGINX uses a centralized configuration approach where all rules must be placed in the main configuration files (typically nginx.conf or included server block files). This design choice gives NGINX a performance advantage—Apache checks for .htaccess files on every request, while NGINX reads configuration only once at startup.

How do I convert Apache RewriteRule to NGINX?

Apache's RewriteRule syntax differs significantly from NGINX's rewrite directive. Apache uses RewriteRule ^pattern$ replacement [flags] while NGINX uses rewrite ^pattern$ replacement flag;. Common flag conversions include: [R=301] becomes permanent, [R=302] becomes redirect, and [L] becomes last. Our converter handles these translations automatically.

What Apache directives are supported?

This converter supports the most commonly used Apache directives including: RewriteRule, RewriteCond, Redirect, RedirectMatch, RedirectPermanent, ErrorDocument, DirectoryIndex, Options, Header directives, and basic authentication settings.

Why migrate from Apache to NGINX?

NGINX offers several advantages over Apache: better performance for static content serving, lower memory footprint, superior handling of concurrent connections through its event-driven architecture, and excellent reverse proxy and load balancing capabilities. Many high-traffic websites use NGINX either as a complete Apache replacement or as a reverse proxy in front of Apache.

Where should I place the converted NGINX configuration?

Place the converted configuration inside the server { } block in your NGINX configuration. On most Linux distributions, this is either:

  • /etc/nginx/nginx.conf (main configuration file)
  • /etc/nginx/sites-available/yoursite.conf (Debian/Ubuntu)
  • /etc/nginx/conf.d/yoursite.conf (RHEL/CentOS)

After making changes, always test with nginx -t before reloading with sudo systemctl reload nginx.

What if the automatic conversion doesn't work correctly?

Complex Apache configurations may require manual adjustment. The converter handles most common patterns, but advanced mod_rewrite logic with multiple conditions or Apache-specific features may need manual translation. Check the NGINX rewrite module documentation for detailed syntax information.

Ready to Install Pre-Built NGINX Modules?

Our RPM repository provides NGINX with HTTP/3, Brotli, ModSecurity WAF, PageSpeed, and 100+ modules for RHEL, CentOS, Rocky Linux, and AlmaLinux. Just yum install and you're done.

Get Repository Access

Used by 1000+ servers. Starting at $10/month.

Related NGINX Resources

 

About the Apache to NGINX converter

NGINX is the leading web server powering the majority of websites in the world. As Apache is being gradually phased out, there’s a need to quickly
migrate from Apache to NGINX web server.
The .htaccess converter helps migrate from Apache to NGINX by converting .htaccess directives to NGINX configuration format.

Converting Apache .htaccess to NGINX like a PRO

Using this online converter can be a convenient way to translate .htaccess files, which are used to configure options for the Apache web server, to NGINX configuration. NGINX is a different web server, and it does not use .htaccess files. Instead, you can use a server block in the NGINX configuration file to specify directives for a particular server or location.

To use this online converter, you will need to provide the .htaccess file directives that you want to convert. The converter will then generate the corresponding NGINX configuration for you.

One thing to keep in mind is that not all .htaccess directives can be directly translated to NGINX. Some directives may require additional configuration or may not be supported by NGINX at all. In these cases, you may need to modify the generated configuration or find alternative solutions.

This online converter is a useful tool for converting .htaccess files to NGINX configuration, especially if you are new to NGINX or if you have a large or complex .htaccess file. However, it’s always a good idea to carefully review the generated configuration and make any necessary adjustments to ensure that it is correct and will work as intended.

Our tool allows you to easily convert a bunch of RewriteRule directives commonly found in Apache’s .htaccess configuration files, to NGINX configuration format.
It also supports a handful of other .htaccess directives.

NGINX main configuration is usually found within /etc/nginx/nginx.conf file and its include files for site-specific directives, e.g. /etc/nginx/sites-available/example.com.conf.

Please find some tips below that will help you understand the converter features better.

The try_files directive

Unlike any other tool out there, we detect and implement the use of the try_files directive as it’s the best practice with NGINX configuration.