.htaccess redirect generator

Runs in your browser

Pick 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.

Apache: .htaccess
nginx

Checked right now in the simulator

    Good to know

      How it works

      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.
      Status codes

      Which status code to pick

      StatusUse for
      301Moved permanentlyMoves you keep: new domain, HTTPS, new URLs. Browsers cache it, so test with 302 first.
      302FoundTemporary: maintenance, tests, anything you’ll undo.
      308Permanent, keeps the methodLike 301, but a POST stays a POST. APIs and forms.
      307Temporary, keeps the methodLike 302 for POST requests.
      FAQ

      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.

      Searches the list of pages on this site. What you type stays in your browser.