Developer Tool
Nginx Redirect Generator
Nginx redirect rule snippet. Use it online on EasyTools99.
Tool area
Everything runs in the browser.
Reference results
| Input | Result |
|---|---|
Old path = /old-guide / Destination = https://example.com/guide/ | rewrite ^/old-guide$ https://example.com/guide/ permanent; |
Old path = /spring / Destination = https://example.com/offers/ | rewrite ^/spring$ https://example.com/offers/ permanent; |
Old path = /manual / Destination = https://docs.example.com/start/ | rewrite ^/manual$ https://docs.example.com/start/ permanent; |
Old path = /hours / Destination = /visit/hours/ | rewrite ^/hours$ /visit/hours/ permanent; |
Old path = /archive/2024 / Destination = /archive/ | rewrite ^/archive/2024$ /archive/ permanent; |
Old path = /map / Destination = https://example.org/visit/map/ | rewrite ^/map$ https://example.org/visit/map/ permanent; |
How it works
The generator wraps the old path in the anchors ^ and $, then inserts the destination and the permanent flag in an Nginx rewrite directive. The flag issues a 301. Check the generated rule in a test configuration before using it on the public path.
Using the result
For a move, test the exact old path and a neighbouring page that should keep its own address. Check the version with a trailing slash as a separate request. If the old URL is used with a query string, confirm whether the replacement should receive those arguments. Review how dots and other pattern characters are interpreted if they appear in the old path. Record the status and destination before changing internal links, and verify that the final page is the one visitors should reach.
Worked examples
- Move a guide to a new path. An editor moves a guide and verifies that its destination opens the intended document.
- Redirect an expired campaign page to the offers index. A manager retires a promotion and checks the destination before updating links.
- Move a manual to a documentation subdomain. A maintainer moves a manual and checks the destination on the documentation subdomain.
Common mistakes
- The path is a regular expression.
- Escape a literal dot.
- A trailing slash changes what matches. Validate with nginx -t and inspect the Location header for a test request. Check that the destination does not lead back to the old path.
FAQ
How do I create a 301 redirect in Nginx?
Enter the path and destination, then use the generated rewrite directive with the permanent flag in the appropriate block.
Does the rule also match child paths?
The anchors bound the entire path. A plain source path matches only that path.
Does the generator modify the server?
It produces a configuration line. Review and apply it in your environment.
