.htaccess to nginx / Caddy Converter & nginx Config Checker
Convert Apache .htaccess to an nginx server block and a Caddyfile, lint nginx.conf for pitfalls, or generate WordPress, Laravel, SPA, proxy configs.
Result
Press “Run” to see the result.
convert (default) turns an .htaccess into an nginx server block and a Caddyfile: mod_rewrite (RewriteCond / RewriteRule with flags L, R=301, NC, QSA, QSD, F, G, OR, RewriteBase, %N back-references), the front-controller pattern (→ try_files), HTTPS and www redirects, Redirect / RedirectMatch, ErrorDocument, DirectoryIndex, Options, Header, mod_expires (→ a map on the content type), mod_deflate, Deny / Allow / Require, <Files> / <FilesMatch>, basic auth, LimitRequestBody, ServerSignature. Each directive gets a confidence (high / medium / low / none) and a note; PHP settings (php_value, php_flag) are moved to a PHP-FPM pool snippet. The output passes nginx -t for the supported directives.
lint checks an nginx configuration statically: unbalanced braces and missing semicolons, if inside location ("if is evil"), alias path traversal (location without / + alias with /), add_header in a child block dropping the parent headers, proxy_pass with a URI in regex locations, variables without resolver, old TLS protocols and weak ciphers, listen 443 without ssl, deprecated listen … http2, CRLF injection through $uri in redirects, unanchored / unsafe PHP locations, autoindex, duplicate server names, missing HSTS / security headers and server_tokens.
generate writes nginx and Caddy configs for static, spa, wordpress, laravel, php or reverse-proxy sites with HTTP → HTTPS and www / apex redirects, Let’s Encrypt paths, gzip (brotli optional), static-file caching and security headers. Test the result with nginx -t or caddy validate before going live.
Use this in your code
curl -X POST "https://apibox.io.vn/v1/webserver-config" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"htaccess":"RewriteEngine On\nRewriteCond %{HTTPS} off\nRewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]\nRewriteRule ^old-page$ /new-page [R=301,L]\nRewriteCond %{REQUEST_FILENAME} !-f\nRewriteCond %{REQUEST_FILENAME} !-d\nRewriteRule . /index.php [L]\nphp_value upload_max_filesize 64M\n","server_name":"example.com","root":"/var/www/example"}'const res = await fetch('https://apibox.io.vn/v1/webserver-config', {
method: 'POST',
headers: {
Authorization: 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({
"htaccess": "RewriteEngine On\nRewriteCond %{HTTPS} off\nRewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]\nRewriteRule ^old-page$ /new-page [R=301,L]\nRewriteCond %{REQUEST_FILENAME} !-f\nRewriteCond %{REQUEST_FILENAME} !-d\nRewriteRule . /index.php [L]\nphp_value upload_max_filesize 64M\n",
"server_name": "example.com",
"root": "/var/www/example"
}),
});
const data = await res.json();
console.log(data);import requests
res = requests.post(
"https://apibox.io.vn/v1/webserver-config",
headers={"Authorization": "Bearer YOUR_API_KEY"},
json={"htaccess": "RewriteEngine On\nRewriteCond %{HTTPS} off\nRewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]\nRewriteRule ^old-page$ /new-page [R=301,L]\nRewriteCond %{REQUEST_FILENAME} !-f\nRewriteCond %{REQUEST_FILENAME} !-d\nRewriteRule . /index.php [L]\nphp_value upload_max_filesize 64M\n", "server_name": "example.com", "root": "/var/www/example"},
timeout=30,
)
print(res.json())<?php
$ch = curl_init('https://apibox.io.vn/v1/webserver-config');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => ['Authorization: Bearer YOUR_API_KEY', 'Content-Type: application/json'],
CURLOPT_POSTFIELDS => '{"htaccess":"RewriteEngine On\\nRewriteCond %{HTTPS} off\\nRewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]\\nRewriteRule ^old-page$ /new-page [R=301,L]\\nRewriteCond %{REQUEST_FILENAME} !-f\\nRewriteCond %{REQUEST_FILENAME} !-d\\nRewriteRule . /index.php [L]\\nphp_value upload_max_filesize 64M\\n","server_name":"example.com","root":"/var/www/example"}',
]);
$response = curl_exec($ch);
print_r(json_decode($response, true));API documentation → Get a free API key
FAQ
Is every mod_rewrite rule converted?
Common patterns are converted with high confidence; complex chains (several conditions, [P], [S], [C]) get low confidence and a note. Always run nginx -t and test the important URLs.
Where do php_value lines go?
Not into nginx: the response gives php_value / php_flag lines for the PHP-FPM pool (or put them in php.ini / .user.ini).
Does lint follow include files?
No: send the full configuration text. It is a static check, not nginx -t.