brandozz
brandozz

Reputation: 1119

Redirecting http to https

I'd like to redirect all of my http traffic to https, currently in my htaccess file I have the following redirecting my http traffic:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
</IfModule>

This redirects all of my non-www to www. What is the best way to make sure all of my bases are covered, which would mean redirecting all of the following:

http://example.com to https://www.example.com
https://example.com to https://www.example.com
http://www.example.com to https://www.example.com

Upvotes: 0

Views: 82

Answers (1)

Panama Jack
Panama Jack

Reputation: 24478

You can use this in your .htaccess file. Just replace example.com with your domain and all bases should be covered.

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

Upvotes: 1

Related Questions