.htaccess Redirect Generator
Write .htaccess rules to force HTTPS, choose www or non-www, redirect old pages and set security headers, with the same rules for Nginx.
Used for the Nginx rules and the comments. The .htaccess rules work for any domain.
Paths start with /. The new address can be a path or a full URL.
Everything happens in your browser. Nothing you enter or choose is uploaded.
How to use the .htaccess generator
- Choose whether to force HTTPS and whether the main address has
www. - List any old pages and where they moved to, one per line, and pick the extras you want.
- Copy the rules into the top of the
.htaccessfile in your site's root folder, then check the result with the redirect checker.
Before you upload
- Keep a copy of your current .htaccess. One typo can take a site offline with a 500 error; restoring the copy fixes it.
- The rules need mod_rewrite (and mod_headers for the headers). Almost every Apache and LiteSpeed host has both.
- Turn on HSTS (part of the security headers) only when every page and subdomain works over HTTPS: browsers will refuse plain HTTP for a year.
Frequently asked questions
Where do I put the .htaccess file?
In your website's root folder, next to index.php or index.html (often public_html). If a .htaccess file is already there, as with WordPress or Basehim, paste these rules at the top, above the existing rules, and keep the rest as it is.
How do I redirect HTTP to HTTPS with .htaccess?
Turn on Force HTTPS. The generator writes a rewrite rule that sends every http:// request to the same address on https:// with a 301. It is combined with the www rule into one redirect, so visitors never go through two hops.
Why do I get "too many redirects" after adding the rules?
Usually the site is behind Cloudflare or another proxy that talks to your server over plain HTTP, so the server never sees HTTPS and keeps redirecting. Turn on "behind Cloudflare or another proxy", or set Cloudflare's SSL mode to Full. Remove any HTTPS redirect added by a plugin or your host as well.
Should I use 301 or 302?
Use 301 for anything permanent: a page that moved, a new domain, HTTPS. Browsers cache 301s hard, so test with 302 first if you are not sure, then switch to 301.
Does .htaccess work on Nginx?
No. Nginx ignores .htaccess files; the rules go in the server block of your site's configuration, followed by a reload. Choose Nginx above for the equivalent rules.
How do I test the rules?
After uploading, open the old addresses in a private window, or use the redirect checker on this site: it shows every hop, its status code, and whether http, https, www and non-www all end in one place.
Related tools
Browse all tools- Redirect Checker Follow every redirect from an address to its final page, with status codes, and check that http, https, www and non-www all end in one place.
- HTTP Headers Checker See every response header a page sends and get a security grade from A+ to F, with the exact header to add for each gap.
- JSON Formatter and Validator Format, validate and minify JSON. Finds the exact line and column of an error and explains it, and can sort keys.
- Favicon Generator Turn an image or a letter into every favicon a site needs: favicon.ico, PNG sizes, Apple touch icon and web manifest, with the HTML to paste.