Nginx Redirect Generator
Updated October 2026Generate Nginx redirect rules using exact-match location blocks and return 301 or 302, for one URL or a whole list. Paste the result into your server block and reload Nginx.
Advertisement
Advertisement
The URL path you want to redirect from (e.g., /old-page). Rules match this exact path; add a second redirect for the trailing-slash version if both exist.
The destination URL (can be relative path or full URL)
301 redirects preserve SEO link equity and are permanent
Enter old and new URLs to generate redirect code
The Nginx Redirect Rule
The generator writes one exact-match location block per old URL with a return directive:
location = /old-page {
return 301 https://www.example.com/new-page$is_args$args;
}The = makes it an exact match, so /old-page is redirected but /old-page/child is not. Nginx checks exact-match locations first and stops as soon as one matches, which makes them the fastest kind of location. $is_args$args carries the original query string across.
Where the Rules Go and How to Apply Them
- Open the configuration for the site, typically
/etc/nginx/sites-available/your-siteor a file in/etc/nginx/conf.d/. - Paste the generated blocks inside the
server { }block that handles the domain, next to the otherlocationblocks. - Check the syntax:
sudo nginx -t. - Reload without dropping connections:
sudo nginx -s reload(orsudo systemctl reload nginx). - Verify from the command line:
curl -I https://www.example.com/old-pageshould show301and the newLocation.
return vs. rewrite, and Other Common Redirects
Use return whenever the destination is a fixed URL. Use rewrite only when part of the old URL has to be captured and reused:
# Move a whole section, keeping the rest of the path
rewrite ^/blog/(.*)$ /articles/$1 permanent;
# Redirect non-www to www (separate server block)
server {
server_name example.com;
return 301 https://www.example.com$request_uri;
}
# Redirect HTTP to HTTPS
server {
listen 80;
server_name example.com www.example.com;
return 301 https://www.example.com$request_uri;
}Old URLs that are identified by their query string (for example /product.php?id=5) cannot be matched by a location, because locations only see the path. For those the generator writes a check on $request_uri instead.
Redirect Generators for Other Servers
The same tool is available preset for each server, plus a combined version:
- 301 redirect generator (all servers)
- .htaccess redirect generator
- PHP redirect generator
- bulk redirect generator
After the redirects are live, confirm each old URL answers 301 and lands on a working page with the broken link checker, and submit a sitemap of the new URLs made with the XML sitemap generator.
How to Use
- 1
Nginx is already selected as the server type
- 2
Enter the old path and the new URL, or switch to Bulk Redirects for a list
- 3
Choose 301 (permanent) or 302 (temporary)
- 4
Copy the generated location blocks into the server { } block of your site configuration
- 5
Test the configuration with nginx -t, then reload with nginx -s reload
Why This Tool Matters for SEO
Nginx has no .htaccess: redirects live in the server configuration, and a mistake there can take the whole site down on reload. Generated rules that use exact-match locations and return are the form the Nginx documentation recommends, because return is evaluated immediately and does not involve the regular-expression engine the way rewrite does.
Frequently Asked Questions
Should I use return or rewrite for a redirect in Nginx?
Use return for redirects. It is simpler and faster because Nginx stops processing and sends the response immediately. Keep rewrite for cases where you need to capture part of the old URL with a regular expression and reuse it in the new one.
Where do I put the redirect rules?
Inside the server { } block for the site, usually in /etc/nginx/sites-available/your-site or /etc/nginx/conf.d/your-site.conf. Location blocks cannot be placed at the http level or inside another exact-match location.
How do I keep the query string when redirecting?
The generated rules append $is_args$args to the destination, which adds the original query string (with its question mark) only when one exists. Remove those variables if you want the query string dropped.
Why is my Nginx redirect not working?
Most often the configuration was not reloaded, the rule is in a different server block than the one handling the request (check server_name and the listen port), or a browser cached an earlier 301. Run nginx -t, reload, and test with curl -I to bypass the browser cache.
Related Tools You Might Like
Meta Tags Generator
Generate optimized meta tags for your pages
Google SERP Preview
Preview how your page appears in Google search results. Optimize titles and descriptions for CTR
Robots.txt Generator
Create and validate robots.txt files for search engine crawlers
JSON-LD Schema Generator
Generate structured data (JSON-LD) for rich snippets
Related Guides
More in Technical SEO tools · All free SEO tools