Nginx Redirect Generator
# Generated with giga.tools Nginx Redirect Generator
location = /old-page {
return 301 /new-page$is_args$args;
}
location ~ ^/docs/(.*)$ {
return 301 https://example.com/guides/$1$is_args$args;
}Other Coding Tools
Generate Nginx Redirect Configuration Online
Create ready-to-use Nginx redirects for individual URLs or complete path sections. Add each source and target, choose a redirect status, then copy the generated location and return directives or download them as a .conf file. Everything runs locally in your browser.
How do I create a 301 redirect in Nginx?
Enter the old path as the source, add the new local path or full destination URL, and keep the status set to 301. The generator uses an exact Nginx location match by default, so only that specific path redirects. Add the output inside the appropriate server block, or let the tool generate a basic server block for you.
What is the difference between exact and path-prefix redirects?
An exact match redirects only one path, such as /old-page. A path-prefix rule redirects a complete section and keeps the remaining path: /docs/install can become /guides/install. Prefix sources and targets end in / so Nginx can safely capture and append the remainder.
Which redirect status should I use?
Use 301 for a permanent page move and 302 for a temporary redirect. Codes 307 and 308 preserve the original HTTP method and request semantics; 307 is temporary and 308 is permanent. For ordinary website migrations, 301 is usually the expected choice.
Can an Nginx redirect preserve query parameters?
Yes. Keep “Preserve Query Strings” enabled to append Nginx’s $is_args$args variables to every destination. A request such as /old-page?ref=email then carries the same parameters to the new URL. Turn the option off when parameters should be discarded or when the target already contains its own query string.
Can I redirect to another domain?
Yes. Enter a complete http:// or https:// URL as the target. Local targets that start with / also work. Generated standalone server blocks keep those redirects relative, preventing an unexpected request Host header from becoming part of the destination.
Where should I place the generated configuration?
Exact and prefix location blocks belong inside the relevant Nginx server block. Enable “Include Server Block” if you want a standalone starting point with listen, server_name, and absolute_redirect off. Before reloading production, save the file and run nginx -t on your server to check the full configuration.
How can redirects help during a site migration?
Redirects preserve working links when page paths or domain names change. Build a rule for each renamed page and prefix rules for moved sections. You can also use the Robots.txt Tester to confirm that search crawlers can access the destinations and the OpenGraph Snippet Generator to prepare metadata for the new pages.