Htaccess Redirect Generator

Generate .htaccess rules for www, HTTPS and 301 page redirects.

Runs instantly in your browser — results update as you type.

What is an .htaccess redirect?

An .htaccess redirect is a rule in Apache's .htaccess configuration file that sends visitors and search engines from one URL to another, usually with a permanent 301 status. It is used to force HTTPS, unify www and non-www versions, and move individual pages.

Redirect types you can generate

  • non-www → www and www → non-www — choose one canonical host.
  • HTTP → HTTPS — send every insecure request to the secure version.
  • HTTP → HTTPS + www or + non-www — both in one rule, so there is a single redirect hop instead of a chain.
  • Single page 301 — move /old-page to a new URL.

Example: HTTPS + non-www in one hop

RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301]

The [OR] makes the rule fire for either condition, and the target is the final URL, so http://www.example.com/page reaches https://example.com/page in one redirect.

How to install the rules

  1. Back up your existing .htaccess (it lives in the website root, e.g. public_html).
  2. Paste the rules near the top, after any existing RewriteEngine On line (you only need it once).
  3. Put redirect rules before CMS rules such as WordPress's # BEGIN WordPress block.
  4. Save and test with the Redirect Checker — you should see exactly one 301 hop.

Behind a proxy or CDN?

If your site sits behind Cloudflare, nginx or a load balancer, Apache may see every request as HTTP and loop forever. In that case check the forwarded protocol instead: RewriteCond %{HTTP:X-Forwarded-Proto} !https, or set the HTTPS redirect at the CDN level.

Not using Apache?

nginx ignores .htaccess. The equivalent is a return 301 https://example.com$request_uri; in the server block. Many hosts (including LiteSpeed) do support .htaccess syntax.

Moving lots of pages? Clean your old and new URL lists first with the Bulk URL Cleaner, then verify every redirect with the HTTP Status Code Checker.

Frequently asked questions

How do I redirect HTTP to HTTPS in .htaccess?

Add RewriteEngine On, then RewriteCond %{HTTPS} off and RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [L,R=301]. The generator writes this for you.

Should I use www or non-www?

Either works for SEO. Pick one, redirect the other with a 301, and use the same version in canonicals, sitemaps and Search Console.

Why does my redirect cause a loop?

Usually a proxy or CDN is sending HTTP traffic to Apache, so the HTTPS rule fires every time. Check X-Forwarded-Proto instead of %{HTTPS}, or redirect at the CDN.

What is the difference between Redirect 301 and RewriteRule?

Redirect 301 (mod_alias) is simple and good for single pages. RewriteRule (mod_rewrite) supports conditions and patterns, which you need for HTTPS and www rules.

Does .htaccess work on nginx?

No. nginx does not read .htaccess files; use a return 301 or rewrite directive in the server configuration instead.