Search tools

Nginx Redirect Generator

List old and new URLs and get fast, exact-match Nginx location blocks, plus HTTPS and www redirects.

Nginx Redirect Generator tool

Nginx configuration

    Test with sudo nginx -t, then reload with sudo systemctl reload nginx. Keep a copy of your working config first.

    Processing runs in your browser.

    Nginx serves a large share of the web, from small VPS sites to large platforms. It doesn’t read .htaccess files, so redirects go straight into the server configuration. That makes them fast, but the syntax is unforgiving and a mistake can stop the server from reloading. This generator writes the common cases in the simplest, safest form.

    What you get

    For the sample list and the domain example.com, the output starts with a server block that catches all plain-HTTP traffic:

    server {
        listen 80;
        server_name example.com www.example.com;
        return 301 https://example.com$request_uri;
    }

    Then one line per redirect, to paste inside your HTTPS server block:

    location = /old-page.html { return 301 /new-page/; }

    location = matches only that exact path, so there are no surprises with similar URLs like /old-page.html.bak.

    Redirecting www over HTTPS

    The port 80 block handles plain HTTP. If you also want https://www.example.com to redirect to https://example.com, add a separate listen 443 ssl server block for the www name that returns a 301 to the canonical host. It needs a certificate that covers the www name.

    Deploy safely

    Copy your current config first, paste the new rules, run sudo nginx -t, and only reload if the test passes. Then check a few old URLs with curl -I to confirm the status code and the new location.

    How to use the Nginx Redirect Generator

    1. List your redirects, one per line: old path, new path or full URL, and an optional status code.
    2. Enter your domain and choose how to handle www and HTTPS.
    3. Check the warnings for duplicates, chains and loops.
    4. Copy the output: the first server block is standalone, and the location lines go inside your main server block.
    5. Test with nginx -t, then reload Nginx.

    Features

    • Uses location = exact matches with return, the fastest kind of Nginx redirect.
    • 301, 302, 307 and 308 status codes, per line or as a default.
    • Port 80 server block that sends HTTP and the non-preferred host to HTTPS in one hop.
    • Handles old URLs with query strings.
    • Detects duplicate sources, self-redirects and redirect chains.

    Frequently asked questions

    Should I use return or rewrite for redirects in Nginx?

    Use return for straightforward redirects. It is simpler and faster because Nginx doesn’t evaluate regular expressions. Keep rewrite for pattern-based rules, such as moving a whole folder.

    Where do the location blocks go?

    Inside the server block that handles your HTTPS site, usually in /etc/nginx/sites-available/yourdomain or a file under /etc/nginx/conf.d/. Exact-match locations take priority over other location blocks.

    How do I check the config before reloading?

    Run sudo nginx -t. It checks syntax and reports the file and line of any error. Only reload, with sudo systemctl reload nginx, when it says the test is successful.

    Does Nginx use .htaccess files?

    No. Nginx has no per-folder config files; all rules go in the server configuration. If you are moving from Apache, convert .htaccess rules into server or location blocks.

    Written by