Skip to content
UniKit

htaccess to nginx

Convert Apache .htaccess into nginx config line by line: RewriteRule / RewriteCond (HTTP_HOST, REQUEST_URI, [L,R=301,QSA,NC]), Redirect / RedirectMatch, ErrorDocument, Options and Deny/Allow / Require — unconvertible lines stay as comments with a warning list.

Runs in your browserEvery computation happens in your browser — your data never leaves this device.

nginx config

Directives

0

Converted

0

Comments

0

Warnings

0

Could not be converted

Everything converted cleanly — nothing needs a manual review.

What this tool does

  • Run a first pass before migrating a site from Apache to nginx: RewriteRule / RewriteCond, Redirect, ErrorDocument, Options and Deny/Allow all produce nginx config.
  • Understand how the two syntaxes map: conditional rewrites become if ($http_host ~* ...) plus rewrite, and redirect status codes become permanent or redirect.
  • Health-check the migration up front: lines that cannot be converted stay as comments and appear in a warning list, so manual work is obvious.
  • Read them side by side as a learning aid — seeing one redirect written in both Apache and nginx beats reading two separate manuals.

Example

Input

RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]

Output

# Generated by UniKit's .htaccess → nginx converter — review it against your own setup
location / {
    # RewriteEngine On: nginx handles rewrites by default, this directive is unnecessary
    if ($http_host ~* "^example.com$") {
        rewrite "^/(.*)$" https://www.example.com/$1 permanent;
    }
}

The result is a snippet that belongs inside a server block; [R=301,L] maps to permanent and [NC] maps to the case-insensitive ~* match.

Frequently asked questions

Can I paste the result straight into nginx.conf?

Mostly, but remember it is a snippet: the rewrite rules are wrapped in location / { ... }, so you need to place the whole block inside the right server block and make sure root, index and try_files are already configured. The generated header comment says as much.

Which directives cannot be converted?

Proxy rewrites marked [P] (nginx needs a separate proxy_pass and upstream), rules whose substitution is "-", block directives such as Files or Directory, complex Require forms, and Options flags with no direct equivalent. Those lines stay as comments and are listed in the warning summary.

Why is the if directive safe here?

The nginx docs warn against abusing if inside location, but for host matching and simple redirects — if ($http_host ...) or if ($request_uri ...) — it is safe. The converter only emits if for those RewriteCond forms and never buries complex logic inside one.

How are Order, Deny and Allow handled?

Deny from all becomes deny all; and Allow from becomes allow with a network range, and a warning is emitted: Apache Order decides whether allow or deny is evaluated first, while nginx matches rules in the order written, so the semantics are not identical and the order needs a manual check.

Does the conversion send my config anywhere?

No. Parsing and generation run in JavaScript inside your browser, the page sends no requests, and internal paths or hostnames from your .htaccess never leave your device.

Keywords:htaccessnginxrewriterewriterulerewritecondredirectapache转换重写规则伪静态errdocument

Related tools