Skip to content
Web Everyone Free Online Website Management Tools
Web Everyone

Colour mode

↑↓ to choose Enter to open Esc to close

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

Runs in your browser Free, no sign-up

Used for the Nginx rules and the comments. The .htaccess rules work for any domain.

HTTPS and www
www
Trailing slash
Trailing slash

Paths start with /. The new address can be a path or a full URL.

Extras

Everything happens in your browser. Nothing you enter or choose is uploaded.

Server

How to use the .htaccess generator

  1. Choose whether to force HTTPS and whether the main address has www.
  2. List any old pages and where they moved to, one per line, and pick the extras you want.
  3. Copy the rules into the top of the .htaccess file 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.

Browse all tools