is it possible to use single certificate in apache for two alias domain name using some kind of redirect using URL rewrite etc? like following. I want to redirect example.com to www.example.com
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteCond %{SERVER_PORT} =443
RewriteRule ^ https://www.example.com%{REQUEST_URI} [L,R=301]
Problem is i have SSL certificate registered for www.example.com domain and i have CNAME example.com but i am getting SSL warning on example.com, can i use above trick to make it work?
You can have a certificate valid for multiple host names when it has multiple Subject Alternative Names or when it’s a wildcard certificate (or both).
Wildcard certificates are not particularly useful for
www.example.comandexample.combecause the dot isn’t part of the pattern, so*.example.comwouldn’t matchexample.com. Such a wildcard certificate would need an additional SAN forexample.comanyway in this case.CAs have various commercial names for certificates with multiple SANs, and often charge extra for then.
However, the
wwwis considered by many a special case. Some CAs will issue a cert with SANs forwww.example.comandexample.comwhen you apply forwww.example.com, without an extra fee.You could also use two distinct certificates but, unless you know all your clients support Server Name Indication (SNI), you would need a separate IP address for each.