Reputation: 724
I know this is a common task but I'm not able to figure this out. We have an SSL-Certificate for www.domain-name.com but not for domain-name.com. When visitors are opening the url https://domain-name.com they get a certificate error.
I've tried the following RewriteRules & -Conditions:
RewriteEngine On
Rewritecond %{https_host} ^domain-name.com [nc]
RewriteRule ^(.*)$ https://www.domain-name.com/$1 [r=301,nc]
Rewritecond %{http_host} ^domain-name.com [nc]
RewriteRule ^(.*)$ https://www.domain-name.com/$1 [r=301,nc]
RewriteCond %{SERVER_PORT} !^443$
RewriteRule (.*) https://%{HTTP_HOST}$1 [R=301,L]
I'm thankful for any help.
Upvotes: 1
Views: 1236
Reputation: 42935
You can try whatever you want, you will not solve the issue by means of rewriting.
Certainly you can redirect requests to the domain you have a valid certificate for. But that is actually not your problem here. Your problem at hand is that whatever reply you send as a result of the original request to the domain you do not have a valid certificate for, the browser will always spit out that warning/error. And it is correct behavior to do so. The reason is simple: the browser receives a reply from a server that claims to be the one requested via https, but that is not able to prove that claim by a valid certificate. This is a clear violation of the security model and has to lead to an error. That is the whole point of validating certificates: to make sure the server sending the answer actually really is the system it claims to be. Without a valid certificate you cannot do that, whatever "workaround" you try.
Your only option is to get a valid certificate for the domain name without that ugly "www" in the name. Actually the best option would be to get a "wildcard certificate", so a single certificate that is valid for both domain names.
Upvotes: 3