.htaccess redirect generator
Runs in your browserPick what you need, type your domain and copy the rule for Apache or nginx. Every result is checked in the simulator before you see it.
Checked right now in the simulator
Good to know
From a choice to a checked rule
Pick what you need, type your domain and copy the result. Each rule comes in two versions: for Apache as a block for your .htaccess, and for nginx as a block for the server configuration.
- Checked before you copy. Every result runs through the same simulator as the .htaccess tester, with the requests listed under “Checked right now”.
- Tested against real servers. The 12 recipes were compared with a real Apache 2.4 and a real nginx.
- With the explanation. The mod_rewrite cheat sheet has these rules and more, each with a note on why it works.
Which status code to pick
| Status | Use for |
|---|---|
| 301Moved permanently | Moves you keep: new domain, HTTPS, new URLs. Browsers cache it, so test with 302 first. |
| 302Found | Temporary: maintenance, tests, anything you’ll undo. |
| 308Permanent, keeps the method | Like 301, but a POST stays a POST. APIs and forms. |
| 307Temporary, keeps the method | Like 302 for POST requests. |
Questions about the redirect generator
Where does the rule go?
For Apache: into the .htaccess in your document root, above the rules of your CMS. Rules run top to bottom, so redirects come first. For nginx: into the server block of your site, followed by a reload.
Apache or nginx: which version do I need?
Apache reads .htaccess files, and most shared hosting runs Apache. nginx has no .htaccess: its rules live in the server configuration. If you are not sure, your host’s documentation says which server it uses.
How do I know the rule works on my site?
The generator runs each result through the simulator and shows the requests it tried. Open it in the tester to try your own addresses, then check the live site with curl -I.