I am trying to get my domain to always redirect to a non-www version and always use https. I found this answer, but it only kind of works.
It works if I try any of the following:
http://domain.com (This will redirect properly to https://domain.com)
http://www.domain.com (This will redirect properly to https://domain.com)
https://domain.com (This does nothing as it is already correct)
However, if I type https://www.domain.com
then I get an error that the domain isn't secure and it doesn't redirect.
Here is my .htaccess rules:
############ START [ENABLE REWRITE ENGINE] ############
RewriteEngine On
RewriteBase /
############ END [ENABLE REWRITE ENGINE] ############
############ START [FORCE NON-WWW AND HTTPS] ############
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule .* https://%1%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule .* https://%1%{REQUEST_URI} [R=301,L]
############ END [FORCE NON-WWW AND HTTPS] ############
I know one option would be to just buy an SSL for the www. version of the domain, but I would prefer to save the money if possible.