Back to All Tools
Client-Side Only

Apache .htaccess Rewrite Rules to Nginx Directives

AST Converter

Convert legacy Apache mod_rewrite directives, 301 redirects, and header settings into idiomatic Nginx server block syntax.

#htaccess to nginx converter#convert apache rewrite to nginx#htaccess to nginx online#try_files WordPress#mod_rewrite migration
Load Production Presets (One-Click Testing)
8 curated templates available
Nginx Compiler Target & Formatting Options
Live Client-Side Recompilation Active
Apache .htaccess Source17 lines • 369 chars
Nginx Directives OutputSyntax Ready
server {
    listen 80;
    listen [::]:80;
    server_name example.com www.example.com;
    root /var/www/html;
    index index.php index.html index.htm;

    # WordPress Core Permalinks
    # Pass-through for index.php (handled natively by try_files / fastcgi)

    # Front Controller / Pretty Permalinks
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    # Prevent directory browsing
    autoindex off;

    # Protect sensitive files
    location ~* ^(wp-config\.php|xmlrpc\.php|\.env) {
        deny all;
    }

    # --- Security Hardening Baseline ---
    # Deny hidden files (e.g. .git, .env, .htaccess)
    location ~ /\. {
        deny all;
        access_log off;
        log_not_found off;
    }

    # Disable direct access to sensitive file types
    location ~* \.(log|sql|bak|sh|inc|config|env)$ {
        deny all;
    }

    # Suppress access and not-found logging for common root assets
    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }
    location = /robots.txt {
        log_not_found off;
        access_log off;
        allow all;
    }

    # --- PHP-FPM FastCGI Handler ---
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/run/php/php-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
}

Rule AST Breakdown

Inspecting every matched directive and its corresponding Nginx translation rationale.

5 Rules Parsed
Engine DirectiveRewriteEngine is active natively in Nginx runtime without requiring an activation flag.
Apache SourceRewriteEngine On
Nginx Equivalent# (Native in Nginx)
Base PathBase path stored: /. Prefixes relative rewrite destinations.
Apache SourceRewriteBase /
Nginx Equivalent# RewriteBase: /
Front ControllerReplaced inefficient mod_rewrite filesystem stat calls with idiomatic Nginx try_files.
Apache SourceRewriteCond !-f & !-d -> RewriteRule . /index.php
Nginx Equivalenttry_files $uri $uri/ /index.php?$query_string;
AutoindexPrevented automated directory file listings.
Apache SourceOptions -Indexes
Nginx Equivalentautoindex off;
Security BlockConverted Apache file protection tag into Nginx location regex block.
Apache Source<FilesMatch ^(wp-config\.php|xmlrpc\.php|\.env)>
Nginx Equivalentlocation ~* ^(wp-config\.php|xmlrpc\.php|\.env) { ... }

100% Client-Side Privacy

Every regular expression, domain rule, and header is parsed locally inside your browser memory. Zero configuration data is ever transmitted to remote APIs or logged.

Idiomatic Nginx Architecture

Translates legacy Apache rewrite rules into modern Nginx conventions, preferring native try_files and valid_referers over brittle conditional hacks.

Production-Ready Hardening

Easily toggle baseline protections against sensitive hidden files (.env, .git), directory listing suppression, and PHP FastCGI execution blocks.