Redirect http:// to https:// and more


thanks for sharing that tool :slight_smile:


Thanks for the great post. I am using the following rewrite rule (without spaces). I am getting http redirected to https and non-www redirected to www. However, my problem is I am getting a 302 redirect for “”. It is redirecting to https:// www. Any idea how to get this to a 301 or just not worry about it?

RewriteEngine on
RewriteCond %{HTTP_HOST} ^website .com [NC]
RewriteRule ^(.)$ http://www. website .com/$1 [L,R=301,NC]
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.
)$ https://%{HTTP_HOST}/$1 [R=301,L]


Hi @jwebb189 this is what I do on cloudways that works for me:

RewriteEngine On 
RewriteCond %{HTTP_HOST} !^domain\.com [NC,OR]
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$$1 [R=301,L]

For the last line add www. if you want it to go to

It returns 301 for me and correctly redirects all attempts to

You can see for yourself at the site I am using these rules for at that is on cloudways.


Got it! Thanks very much!


Hi, pff nothing worked and then this finally worked:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^ [NC]
RewriteRule ^(.*)$$1 [L,R=301,NC]
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

This makes all the http to https-www and non-www to https-www.

Check it with

Also make sure that whenever you change the htaccess file that you refresh the server and purge the varnish.


I was struggling with this tonight, had to change my settings, and this finally did the trick for everything i need - including passing string variables in urls.


you might also want to try the following set of generic directives – no specific domain name needed:

# Force HTTPS & URL-canonicalization
<IfModule mod_rewrite.c>
	RewriteEngine On
	RewriteCond %{HTTPS} off [OR]
	RewriteCond %{HTTP_HOST} ^www\. [NC]
	RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
	RewriteCond %{HTTP:X-Forwarded-Proto} !https
	RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]

see Jeff Starr:
Redirect HTTP to HTTPS
Canonical www via .htaccess