Zahid Awais Get a free audit

Free Apache to Nginx redirect converter

Paste the redirect part of your .htaccess file and get Nginx rewrite, return and if rules, with every line it cannot convert safely flagged.

By Zahid Awais · Technical SEO tools · Free, private, no sign-up

Converts Redirect, RedirectPermanent, RedirectTemp, RedirectMatch and RewriteRule with R, L, NC, QSA, QSD, F and G flags, plus RewriteCond on HTTP_HOST, HTTPS, SERVER_PORT, REQUEST_URI, QUERY_STRING and request headers. Anything else is flagged, not guessed. Assumes the .htaccess file is in the site root. Runs in your browser.

Result
0Lines read
0Converted
0Flagged
Flags and notes
    Apache to Nginx Redirect Converter: what it does and an example result

    The free htaccess to Nginx converter turns the redirect rules from an Apache .htaccess file into Nginx rewrite, return and if lines. It keeps status codes, case rules and query string behaviour, and it flags every line it cannot convert safely instead of guessing. It runs in your browser.

    Quick answer

    An htaccess to Nginx converter rewrites Apache redirect rules in Nginx syntax, because Nginx does not read .htaccess files. Redirect and RedirectMatch become rewrite or return lines, RewriteRule patterns gain the leading slash Nginx sees, and conditions on host or HTTPS become if blocks. Always test the result with nginx -t.

    What is an htaccess to Nginx converter?

    An htaccess to Nginx converter is a tool that translates Apache configuration into the directives Nginx understands. Apache reads redirect rules from .htaccess files in each folder. Nginx has no per-folder files, so the same rules have to move into the server block of the site's Nginx configuration, written with the rewrite module directives return, rewrite, if and set.

    The hard part is the small differences. In .htaccess, Apache strips the leading slash before a RewriteRule pattern is matched, while Nginx matches the full path. Apache's [R] flag defaults to 302, and a target with its own query string drops the old one unless you add [QSA]. This converter handles those cases line by line, and it flags proxies, file checks, internal front controller rewrites and containers such as <Files> for you to rewrite by hand.

    How do you use the Apache to Nginx Redirect Converter?

    How to use the Apache to Nginx Redirect Converter: enter details, see the result and copy it
    Real screenshot of the Apache to Nginx Redirect Converter with the example input from this page.
    1. Open your .htaccess file and copy the redirect part: Redirect, RedirectMatch, RewriteCond and RewriteRule lines.
    2. Paste it into the box. Comments and RewriteEngine lines are read but need no Nginx version.
    3. Read the flags: each line the tool could not convert says why and what to use instead.
    4. Copy the Nginx rules into the server block of your site, above the location blocks.
    5. Run nginx -t, reload Nginx and test a few old URLs with a redirect checker before you switch traffic.

    Why does a RewriteRule need a leading slash in Nginx?

    Because the two servers match different strings. Apache's per-directory rewrite docs say that in .htaccess context "the directory prefix is stripped", so a rule in the site root sees blog/post, not /blog/post. They add that a pattern beginning with ^/ "will never match in this context". Nginx's rewrite directive matches the full URI, which always starts with a slash. The converter adds that slash, so ^blog/(.*)$ becomes ^/blog/(.*)$, and it flags ^/ patterns that Apache already ignores.

    How are RewriteCond lines converted?

    Each condition becomes an Nginx if test: %{HTTP_HOST} becomes $http_host, %{HTTPS} off becomes $https != "on", and [NC] becomes the case-insensitive ~* operator. Nginx cannot combine conditions inside one if, so two or more conditions are joined with set variables, keeping Apache's rule that [OR] binds two conditions while the rest must all match. Back references such as %1 become named captures. Tests on files and folders, such as -f and -d, are flagged.

    What happens to query strings when you convert?

    The converter keeps Apache's behaviour. Apache's flags documentation says that when the target has a query string, the default is "to discard the existing query string", while [QSA] combines them and [QSD] drops the old one. In Nginx, a rewrite target with its own query string keeps the old arguments too, unless the target ends with a question mark. So targets without [QSA] get a trailing ?, and return lines get $is_args$args where Apache would keep the query string.

    Quick reference: Apache to Nginx

    Apache (.htaccess)NginxNote
    Redirect 301 /old /newrewrite ^/old(/.*)?$ /new$1 permanent;Prefix match, rest of the path kept
    Redirect gone /oldif ($uri ~ "^/old(/.*)?$") { return 410; }410 Gone
    RewriteRule ^a$ /b [R=301,L]rewrite ^/a$ /b permanent;Leading slash added
    [R] with no coderewrite ... redirect;Both send 302
    [R=307] or [R=308]if (...) { return 308 ...; }rewrite only sends 301 or 302
    [NC](?i) in rewrite, ~* in ifCase-insensitive
    [QSD] or a target with ?Target ends with ?Stops Nginx adding the old query string
    RewriteCond %{HTTPS} offif ($https != "on")True for plain HTTP requests
    [P], -f, -d, FlaggedRewrite by hand

    Worked example

    Example

    Example: the default box has 12 lines from a typical .htaccess file. The tool reads 10 of them (the comment and blank line are skipped) and converts 6 redirect rules. The HTTPS and www rule, with two conditions joined by [OR], becomes a set $an1 0 line, two if tests that set $an1 to 1 and a final if that runs the rewrite. Redirect 301 /old-page/ becomes rewrite ^/old-page/(.*)$ with the rest of the path kept, the [NC] rule gets (?i), the 302 to /shop/?ref=old gets a trailing ? so the old query string is dropped as in Apache, and Redirect gone becomes return 410. The Header set line is flagged, because it is not a redirect.

    Learn more

    Frequently asked questions

    Does Nginx support .htaccess files?

    No. Nginx reads its settings from its own configuration file, nginx.conf by default, and changes apply only after a reload or restart. Rules left in .htaccess files are ignored, so redirects must be converted and added to the server block.

    Is it safe to use if in Nginx?

    Nginx if blocks cannot be nested or combine tests, so the converter keeps them simple: only return, rewrite and set, at server level. For HTTPS and www redirects, a separate server block with return 301 is simpler, and the tool says so.

    Why are some lines flagged instead of converted?

    Some Apache features have no exact Nginx twin, such as proxying with [P], checks for real files with -f and -d, or containers like Files. Guessing could break the site, so the tool explains each one and suggests what to use instead.

    How do I convert the WordPress .htaccess block?

    You do not convert it line by line. The WordPress block sends requests for missing files to index.php, which in Nginx is a single try_files line inside location /. The tool flags that rule and shows the try_files line to use.

    Can I test the converted rules before going live?

    Yes. Run nginx -t to check the syntax, reload on a staging server, then request a few old URLs with curl -I or a redirect checker. Compare the status code and Location header with what the Apache server returns today.

    Do redirects keep their SEO value after moving to Nginx?

    Yes, as long as the status codes stay the same. Google treats 301 and 308 as permanent redirects that signal the target should be canonical, and 302, 303 and 307 as temporary. The server software does not matter to Google.

    Sources

    Checked 23 Oct 2026. Facts checked against these official pages. Read how I check facts in my editorial policy.

    Related free tools

    All free tools

    Nginx Redirect Generator

    An Nginx redirect generator is a tool that turns old and new URLs into Nginx configuration such as location =…

    Trailing Slash Checker

    Finds mixed trailing slash URLs and duplicate pairs, then writes Apache and Nginx rules.

    Redirect Map Generator

    A redirect map generator is a tool that builds the old URL to new URL table you need before a site migration.…

    Want a full audit instead?

    Send your website and I will check it for you, free.

    Get my free audit
    Chat on WhatsApp
    Free updates

    Get new tools, guides and coupons first

    One short email when something new goes live: articles, free SEO tools, package updates, discounts and price alerts. No spam, unsubscribe in one click.