.htaccess Redirect Generator

Generate redirect rules for Apache .htaccess: force HTTPS, pick www or non-www, move pages or a whole domain. The matching Nginx config is shown alongside.

What do you want to redirect?

Site-wide
Moved pages optional

One per line: the old path, a space, then the new path or full URL.

Moving to a new domain optional

Every URL on your domain goes to the same path on the new one. Use this on the old site.

Generated rules

.htaccess, at the top of the file

Before you add these rules

  1. Make sure HTTPS works on every address first. Redirecting to an address without a valid certificate shows visitors a security warning.
  2. Back up your current .htaccess. A typo can take the whole site down with a 500 error.
  3. Put the rules above any existing ones, including those added by WordPress or other software.
  4. Test in a private window, then check the result with the Redirect Checker.

Common problems

  • Too many redirects. Usually an HTTPS rule here combined with a CDN or proxy set to connect to your server over HTTP, such as Cloudflare's Flexible SSL mode. The rules here check the X-Forwarded-Proto header to avoid that, but setting Cloudflare to Full (strict) is the real fix.
  • Nothing happens. The host may not allow .htaccess overrides, or mod_rewrite is not enabled. Ask your host, or use the Nginx version if your server runs Nginx.
  • Browser keeps the old redirect. Browsers cache 301 redirects. Test with a private window or a different browser while you are changing rules.

Limitations

  • Old paths are matched exactly, with or without a trailing slash. For patterns, such as moving a whole folder, edit the generated rule or write a RewriteRule with a regular expression.
  • Query strings are passed through unchanged. Redirects based on query strings need extra RewriteCond lines.
↑ ↓ moveEnter openEsc close

Expanded view