Nginx Redirect Generator — return 301, Force HTTPS and www
Generate fast Nginx server block 301 redirects and non-www canonicalization.
The server blocks above stand alone; paste the location and if lines inside the main site's server block, then run nginx -t and reload.
✓ 5 redirects ready, each going straight to its final URL in one hop.
When to use the Nginx return 301 & rewrite Rule Generator
return, not rewrite
Redirects use return 301 inside exact-match locations, the approach Nginx's documentation recommends because it needs no regular expression and is processed fastest.
Server blocks for HTTPS and www
HTTP requests and the secondary host name are sent to https:// on the main host in one hop, using $request_uri so path and query stay intact.
Old query-based URLs
URLs such as produk.php?id=7 are matched against $request_uri at server level, so the original PHP page keeps serving other queries instead of turning into a 404.
Tested on a real Nginx
The output passes nginx -t, and every example URL is requested from a running Nginx with its status code and Location compared one by one.
Frequently asked questions
Where do the location lines go?
Inside the main site's server block, usually in /etc/nginx/sites-available/site-name or /etc/nginx/conf.d/. The HTTP and www server blocks stand alone in the same file.
Is the query string carried over?
return does not carry the query automatically, so this tool adds $is_args$args when keeping the query is on. For query-based rules the old query is deliberately dropped.
What about thousands of redirects?
For very long lists, use a map block from $request_uri to the target URL with a single if and return. A map stays fast even with thousands of lines.
Do redirects affect SEO?
A 301 passes ranking signals to the new URL. Avoid redirect chains and redirects to unrelated pages, because Google can treat those like a page that was not found.
Similar tools
- Google Analytics UTM Campaign Link BuilderBuild GA4 campaign links: encoded utm_ values, existing parameters and the #fragment kept, lowercase and space options, presets, many URLs at once and .txt/.csv export.
- Apache .htaccess 301/302 Redirect GeneratorGenerate Apache mod_rewrite 301 permanent redirects and HTTPS enforcement.
- Cloudflare Bulk & Dynamic Redirect Rule BuilderExport CSV lists for Cloudflare Bulk Redirects or dynamic rule expressions.
- HTTP Set-Cookie Header Attribute InspectorParse raw Set-Cookie headers to inspect Secure, HttpOnly, SameSite and Max-Age.