0

I have a certificate issued by AWS for my domain, and as informed I configured it on register.com. Problem is that when I open the site with www.example.com it appears as an invalid certificate, but when I open it directly with https://example.com it appears a valid certificate.

I am using NodeJS as a server, how do I redirect to always open the domain like https://example.com ?

Now is working like this:

app.use((req, res, next) => {
    res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
    res.setHeader('Access-Control-Allow-Origin', '*');
    res.setHeader('Access-Control-Allow-Headers', 'Locale, X-Requested-With, Content-Type, Origin, Authorization, Accept, Client-Security-Token, Accept-Encoding, Content-Encoding');
    res.setHeader('Access-Control-Expose-Headers', 'Locale');

    if ((req.headers["x-forwarded-proto"] || "").endsWith("http")) {
        res.redirect(`https://${req.headers.host}${req.url}`); 
    }    
    next();
});

My certificate

enter image description here

Roberto Vieira
  • 349
  • 1
  • 3
  • 12

1 Answers1

1

You have to register your SSL certificate for both www.example.com and example.com. Registering only one, will not work because www.example.com will be considered as different than example.com.

enter image description here

Marcin
  • 215,873
  • 14
  • 235
  • 294
  • Thanks.. First time I do this configuration. Can I redirect any request to https://example.com? I saw, I think I have ti generate another certificate to fix this issue. – Roberto Vieira Mar 09 '21 at 01:15
  • I saw this post about my doubt about add domain to the existing post -> https://stackoverflow.com/questions/43194494/how-to-add-a-domain-to-an-existing-ssl-certificate-on-aws – Roberto Vieira Mar 09 '21 at 01:21
  • @RobertoVieira You can redirect. But for SSL cert, you have to delete the existing one, and create new one with both domains. – Marcin Mar 09 '21 at 02:15