I am managing two domain names and want to redirect one to the other. I set up a domain forwarding with 301 permanent redirection from domain S (source) to domain T (target). The server on domain T redirects all HTTP to HTTPS. The browser is redirected if I visit http://<domain-S>
.
If I visit https://<domain-S>
(note the S for TLS), I see:
Firefox detected a potential security threat and did not continue to <domain-S>. ...
Firefox does not trust this site because it uses a certificate that is not valid for <domain-S>. The certificate is only valid for the following names: shortener.secureserver.net, www.shortener.secureserver.net
Error code: SSL_ERROR_BAD_CERT_DOMAIN
Please note that the HTTPS configuration is working well for <domain-T>
. I believe that the problem is that the SSL certificate for https://<domain-T>
is being served for https://<domain-S>
.
How can I redirect the domain before serving the certificate?
You must provide a valid certificate when the browser visits
https://<domain-s>
, the certificate check is performed before processing the page content/redirects/... and this is by design.If you can't create a certificate for domain
S
and another for domainT
, you can list both domains inSubject Alternative Name
of your certificate: RFC5280, Section 4.2.1.6There is no configuration change that will accomplish what you're trying to do - the problem is that the browser knows that the user tried to browse to domain-s and the website that was served up is protected by a certificate signed for domain-t. From the browser's perspective, domain-t is invalidly impersonating domain-s. The only way to change this would be to a Multi-Domain/SAN Certificate that is authoritative for both domain-s and domain-t. Alternatively, if domain-t is a subdomain of domain-s, you could use a wildcard certificate.
In short, this is TLS doing it's job - notifying the user that the server they reached is actually at domain-t instead of where the user tried to go.
This does exactly what you're trying to do using nginx assuming they reside on different IPs (you didn't specify):
If they reside on the same server/IP then you need to setup and use SNI which is supported on most modern browsers or use a common TLS certificate.