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

(Talonwp) #21

thanks for sharing that tool :slight_smile:

(Jwebb) #22

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]

(Dillyn Barber) #23

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.

(Jwebb) #24

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.

(forrestt williams) #26

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.