This Nginx redirect generator turns a list of old and new URLs into 301 rules, or forces HTTPS and www for a whole domain. It checks every line for redirect loops and chains, then gives you curl commands to test the result. The rules work in aaPanel and on any Nginx server.
Nginx redirect generator
301 rules for pages, HTTPS and www, with loop checks and test commands.
Try:
Your rules will appear here.
The commands to check your redirects will appear here.
Where to paste: put the rules inside your site’s server { } block, above the first location block. In aaPanel open Website, click Conf next to your site, choose Config file, paste them there and Save. On other servers run nginx -t (it only checks the config for errors) and then reload Nginx. Run the test commands in a Linux or macOS terminal, or in aaPanel’s Terminal.
How to use the generator
- Choose Pages to redirect single URLs, or Whole domain to force HTTPS, pick www or non-www, or move the site to a new domain.
- For pages, write one redirect per line: the old path, a space, then the new path or full URL. Add your site address so the tool can catch loops.
- Click Generate the rules and copy them.
- Paste them into your site's server block (steps below), save, and run the test commands. Each one should print 301 and the new URL.
Where to paste the rules in aaPanel
- Open Website, click Conf next to your site and choose Config file.
- Copy the whole file into a text file on your computer first, so you can undo the change in seconds.
- Paste the rules inside the
server { }block, just above the firstlocationline, and click Save. - Purge Cloudflare and your cache plugin, then run the test commands.
aaPanel also has a Redirect tab that adds one redirect at a time. It is fine for one or two URLs. For a list, or when you want rules you can read and review in one place, paste the generated rules instead. On a server without a panel, add the rules to the site's server block, run nginx -t (it only checks the config for errors) and reload Nginx.
What the generated rules look like

One line in the box, /old-page/ /new-page/, becomes two exact-match rules, one with and one without the trailing slash:
location = /old-page/ { return 301 /new-page/; }
location = /old-page { return 301 /new-page/; }
location = matches only that exact path, so a rule can never catch other URLs by accident, and Nginx checks exact matches before its other locations. return 301 answers straight away, before WordPress or PHP even load.
Which redirect code to choose
- 301: the page has moved for good. Google treats it as permanent and shows the new URL in search over time. Use it for almost every SEO redirect.
- 302: a temporary move, such as a page that is down for a few days. Google keeps the old URL in search.
- 308 and 307: permanent and temporary like 301 and 302, but the browser must resend a form submission (a POST request) as it was. Normal pages do not need them.
Mistakes the generator helps you avoid
- Redirect chains: if A goes to B and B goes to C, point A straight to C. The tool warns you when a new URL is redirected again further down your list.
- Loops: a URL that leads back to itself, directly or through other lines, never loads. With your site address filled in, the tool refuses them.
- Two HTTPS redirects: if aaPanel's own Force HTTPS switch is on and you add the domain rules too, visitors get two redirects. Keep one.
- Cloudflare Flexible SSL: with Flexible, Cloudflare talks to your server over plain HTTP, so a force-HTTPS rule loops forever. Use Full or Full (strict).
When to use something else
If you only need a few redirects and change them often, Rank Math's Redirections module manages them from the WordPress dashboard without touching Nginx. Server rules are faster because they run before WordPress loads, and they keep working if a plugin is switched off. If your server runs Apache or OpenLiteSpeed instead of Nginx, these rules will not work there; those servers use .htaccess rules.
FAQ
How long should I keep a redirect?
As long as you can. Google's site move guide says to keep redirects for at least one year, and old links and bookmarks keep working only while the redirect exists. After a domain move, also keep paying for the old domain.
Is the query string kept?
Only if you tick "Keep the query string". Without it, a visitor who opens /old-page/?utm_source=x lands on the clean new URL. With it, the ?utm_source=x part travels with them.
Is it safe to paste the generated rules?
The generator accepts only clean paths and URLs. It refuses characters that could change your Nginx config, such as semicolons, braces, quotes, dollar signs and spaces, and it builds the output as plain text in your browser. Keep the copy of your config from step 2 anyway, so any change is easy to undo.
Why does my old URL still load with 200?
Usually a cache is answering. Purge Cloudflare and your cache plugin and test again. If it still shows 200, check that you pasted the rules into the right site's config file and that the save did not show an error.
