I recently set up a new website running off Wordpress which is working nicely. Since I wanted to have an SSL certificate for the website I thought I'd use Let's Encrypt since I've been hearing a lot of good things about it.
Well I have to agree it took 30 seconds to get SSL working on my domain but there is one small problem.
Let's encrypt has set the following rules:
http://domain.com -> https://domain.com (fails)
http://www.domain.com -> https://www.domain.com (works)
The certificate is only for www.domain.com which is annoying. In the past all the SSL certificates I bought included both domain.com and www.domain.com in the SSL certificate. Not sure if I did something wrong when getting the Let's Encrypt certificate but that is the way it is.
All I need to do is change things so that http://domain.com redirects to https://www.domain.com.
But since I'm new with Apache I have no idea how to do it. I have the following redirect rule in my .htaccess file but it doesn't seem to help since Apache seems to redirect before the request hits the rewrite rule in the .htaccess file. Here is the rule:
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
So I'm pretty stuck on this particular problem. The site correctly redirected from domain.com to www.domain.com before I added the SSL certificate so it seems to be something that Let's Encrypt automated install did and I can't find it.
This is the rewrite rule Let's Encrypt added to my Apache configuration file:
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [L,QSA,R=permanent]
I think it has something to do with the above line but I don't know what.
Any help would be appreciated.