How to use the Htaccess Redirect Generator
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.

