01What is Htaccess to Nginx?
Apache reads .htaccess files on every request. nginx has no such thing, so moving a site means turning those rules into directives inside a server block. This converter does that for the rules most sites actually use, line by line, as you type. A RewriteRule becomes an nginx rewrite. The flag decides the ending: R=301 maps to permanent, a bare R or R=302 maps to redirect, and other codes become a return. nginx matches against the full URI, while per-directory .htaccess rules see the path without its leading slash. So the tool adds that slash, and ^blog/(.*)$ turns into ^/blog/(.*)$ with $1 still pointing at the same group. Query strings follow the mod_rewrite docs. A target with its own query replaces the old one unless QSA is set, and QSD drops it. RewriteCond lines are translated, not thrown away. The common force-HTTPS pair becomes an if block on $https that returns 301 to $http_host$request_uri. Host, user-agent, query-string and header checks become if blocks too. A %1 back-reference becomes a named capture, and several conditions, including [OR] chains, are combined with flag variables because nginx cannot nest if blocks. The !-f and !-d pair that WordPress and Laravel use is turned into try_files with a named fallback location. Here is what a real run gives for that pair followed by RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]. You get location / { try_files $uri $uri/ @htaccess_rewrite; } and a location @htaccess_rewrite that holds rewrite ^/(.*)$ /index.php?q=$1 last. Redirect and RedirectMatch, Header set (keeping always), ErrorDocument and DirectoryIndex are handled as well. RewriteEngine and IfModule wrappers turn into comments. Some rules have no safe translation. A condition on a time variable, a symlink test or a numeric comparison leaves the whole rule commented out under NOT CONVERTED, with the reason. It never becomes an unconditional redirect, which could loop your site. Directives such as Options, AuthType or php_value are marked as unsupported. The output also assumes the .htaccess lived in the document root. Rules from a subfolder need that path added by hand. Your rules are parsed by the page's own script, so nothing about your server layout is uploaded. Always run nginx -t before reloading.
Sysadmins and PHP developers use it when moving a site from Apache to nginx and they need a first draft of the server block from an existing .htaccess file. The tool runs entirely in your browser, so your data never leaves your device.
02How to use Htaccess to Nginx
- Paste your rules into .htaccess Input, or load Basic Redirects, Security Headers, Full Configuration or WordPress.
- Check the type badges (redirect, rewrite, header, error, index, unknown) to see what was recognised.
- Read Nginx Output and look for lines marked NOT CONVERTED, Unsupported directive or WARNING.
- Click Copy, paste the result inside the right server block, then run nginx -t before reloading.
03Worked examples
- Input:
Redirect 301 /old /new - Result:
rewrite ^/old(/.*)?$ /new$1 permanent; - Apache's Redirect also matches subpaths, so /old/page goes to /new/page. The optional group keeps that. The header comment line is trimmed here.
- Input:
RewriteEngine On RewriteRule ^blog/(.*)$ /posts/$1 [R=301,L] - Result:
# RewriteEngine On (not needed: nginx rewrites are always on) # RewriteRule ^blog/(.*)$ /posts/$1 [R=301,L] rewrite ^/blog/(.*)$ /posts/$1 permanent; - The pattern gains a leading slash. The original rule is kept above as a comment.
- Input:
RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L] - Result:
if ($https != "on") { return 301 https://$http_host$request_uri; } - Trimmed to the directives. A whole-path redirect becomes a return with $request_uri, which keeps the query string.
- Input:
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC] RewriteRule ^(.*)$ https://%1/$1 [R=301,L] - Result:
if ($http_host ~* "^www\.(?<htc1_1>.+)$") { return 301 https://$htc1_1$request_uri; } - Trimmed to the directives. [NC] becomes ~* and the %1 back-reference becomes a named capture.
- Input:
RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?q=$1 [L,QSA] - Result:
location / { try_files $uri $uri/ @htaccess_rewrite; } location @htaccess_rewrite { rewrite ^/(.*)$ /index.php?q=$1 last; } - Trimmed: the real output adds comment lines above. The front-controller pattern becomes try_files with a named location.
- Input:
RewriteCond %{TIME_HOUR} ^22 RewriteRule ^(.*)$ /night [R=302,L] - Result:
# NOT CONVERTED (RewriteCond: %{TIME_HOUR} has no nginx equivalent). Translate by hand: # RewriteCond %{TIME_HOUR} ^22 # RewriteRule ^(.*)$ /night [R=302,L] - Rules it cannot translate safely stay commented out instead of becoming an unconditional redirect.
04Common use cases
- Moving a WordPress or Laravel site from shared Apache hosting to an nginx VPS and keeping its pretty permalinks
- Converting a long list of Redirect 301 lines left over from a site restructure
- Porting X-Frame-Options and other security headers from .htaccess into a server block
- Rewriting a www to non-www redirect that uses a %1 back-reference from RewriteCond
- Auditing an old PHP app's .htaccess to see which rules need manual work before a server switch
- Translating ErrorDocument and DirectoryIndex settings when a site moves behind nginx
05Tips
- If you already have a location / block, merge the generated try_files line into it. Two location / blocks in one server is a config error.
- A converted force-HTTPS if block works, but a separate port 80 server block that does return 301 is the usual nginx pattern.
- nginx add_header only applies to 2xx and 3xx responses unless the always parameter is present. Header always set keeps it for you.
- add_header in a location block replaces the headers inherited from the server block, so keep them together.
- The [C], [S] and [N] flags change rule flow and get a WARNING line. Check those rules by hand.
06Related concepts
mod_rewrite, nginx location blocks, URL rewriting, HTTP redirects, Server migration.
Frequently Asked Questions
What is Htaccess to Nginx?
Htaccess to Nginx is a free, browser-based developer tool on AIDToolStack. Convert Apache .htaccess to nginx config It requires no installation or sign-up and works entirely in your browser.
Is Htaccess to Nginx free to use?
Yes. No sign-up, no fees and no usage cap.
Does Htaccess to Nginx store my data?
No. It runs in your browser; nothing is uploaded.