How to fix an SSL certificate with the wrong hostname or subdomain
A certificate name mismatch happens when the certificate your server sends does not list the exact hostname in the address bar. The padlock is replaced by a full-page warning such as NET::ERR_CERT_COMMON_NAME_INVALID in Chrome or SSL_ERROR_BAD_CERT_DOMAIN in Firefox, and most visitors leave. It usually shows up on www, a new subdomain or an extra domain alias, while the main address works perfectly. Search engines and AI crawlers that hit the warning cannot fetch the page either. This guide shows you how to read the names a certificate really covers, why the server may be sending a different certificate from the one you installed, and how to issue and attach the right certificate to every hostname you use.
- What a hostname mismatch error means
- Why the certificate does not match
- How to see which names your certificate covers
- Issuing a certificate that covers every name
- Making the server send the right certificate
- Worked example: www and a shop subdomain
- The fix, step by step
- Edge cases worth knowing
- Keeping every hostname covered
- Questions and answers
What a hostname mismatch error means
When a browser connects over HTTPS it asks the server for a certificate, then checks three things: that the certificate was issued by an authority it trusts, that it is in date, and that it was issued for the hostname being visited. A mismatch error means the first two checks passed but the third failed. The certificate is genuine, it is simply for a different name.
The name check uses the Subject Alternative Name (SAN) list inside the certificate. The older Common Name field is ignored by Chrome, Edge, Firefox and Safari, so a certificate with CN=example.com and no SAN entries fails even on example.com. Every hostname you serve must appear in the SAN list, either exactly or through a wildcard.
| Browser | What the visitor sees |
|---|---|
| Chrome and Edge | Your connection is not private, with NET::ERR_CERT_COMMON_NAME_INVALID |
| Firefox | Warning: Potential Security Risk Ahead, with SSL_ERROR_BAD_CERT_DOMAIN |
| Safari | This Connection Is Not Private, naming the site the certificate is really for |
| curl | SSL: no alternative certificate subject name matches target host name |
Because the error is about names, it is very common for one address to work and another to fail on the same site. https://example.com loads, while https://www.example.com or https://shop.example.com shows the warning. That pattern tells you the certificate itself is fine and the fix is to cover the missing name or to send the right certificate for it. If instead every hostname fails with an authority or date error, see fixing an untrusted certificate.
Why the certificate does not match
Almost every mismatch comes from one of a small number of causes. Find yours before changing anything, because the fix for a missing SAN is different from the fix for a server that sends the wrong certificate.
| Cause | Typical sign | Fix |
|---|---|---|
| www or the bare domain is missing from the SAN list | example.com works, www.example.com fails, or the other way round | Reissue with both names |
| New subdomain added after the certificate was issued | shop.example.com fails, main site works | Expand the certificate or issue one for the subdomain |
| Wildcard used for the bare domain or a deeper level | *.example.com installed, but example.com or a.b.example.com fails | Add the bare domain as a SAN, or a second wildcard for the deeper level |
| No matching virtual host, so the server's default certificate is sent | Certificate names the hosting server or another customer's site | Create an HTTPS virtual host for the name |
| DNS points the name at a different server | Certificate belongs to an old host, a parking page or a platform | Correct the DNS record or set the custom domain on the platform |
| CDN or proxy does not cover the hostname | Only proxied names fail, or only deep subdomains fail | Add the hostname to the CDN edge certificate |
| Visiting by IP address or an internal name | https://203.0.113.10 or https://server01 fails | Use the public hostname; public authorities do not issue for internal names |
How wildcards really behave
A wildcard covers exactly one label in the leftmost position. *.example.com matches www.example.com and shop.example.com, but not example.com itself and not dev.shop.example.com. Most certificate authorities, including Let's Encrypt, add the bare domain alongside the wildcard if you ask for both names, which is what you normally want.
How to see which names your certificate covers
In Chrome, click the icon to the left of the address, choose the connection details, then open the certificate viewer and look at the Subject Alternative Name field under Details. That shows you what the browser received, which may not be the certificate you think you installed.
From a terminal, OpenSSL tells you exactly what the server sends for a given name. The -servername option sets SNI, the field the server uses to choose a certificate, so always set it to the hostname that fails:
openssl s_client -connect www.example.com:443 -servername www.example.com </dev/null 2>/dev/null \
| openssl x509 -noout -subject -issuer -dates -ext subjectAltName
Typical output for a certificate that is missing www:
subject=CN = example.com
issuer=C = US, O = Let's Encrypt, CN = R11
notBefore=Sep 2 08:14:21 2026 GMT
notAfter=Dec 1 08:14:20 2026 GMT
X509v3 Subject Alternative Name:
DNS:example.com
Only one name is listed, so www.example.com cannot pass. If the SAN list shows a completely different domain, such as the host's server name, the server is falling back to its default certificate because no HTTPS site is set up for the name you asked for.
Quick checks with curl and DNS
curl -vI https://www.example.com 2>&1 | grep -Ei "subject|issuer|SSL"
dig +short www.example.com
dig +short example.com
Compare the two DNS answers. If www is a CNAME to a platform or resolves to an older IP address, the certificate you installed on your main server is never reached. You can also run the hostname through the security audit, which reports the names on the certificate and whether the visited host is among them.
Issuing a certificate that covers every name
Make a list of every hostname a visitor or crawler might use: the bare domain, www, each subdomain, and any extra domains that redirect to the main one. Every name on that list needs a valid certificate, including the ones that only redirect.
Certbot on your own server
Issue one certificate for both the bare domain and www, using the nginx or Apache plugin so the configuration is updated for you:
sudo certbot --nginx -d example.com -d www.example.com
sudo certbot --apache -d example.com -d www.example.com
To add a subdomain to an existing certificate, run the command again with the full list of names plus --expand. Certbot replaces the certificate with one that carries all the names:
sudo certbot --nginx --expand -d example.com -d www.example.com -d shop.example.com
sudo certbot certificates
The second command lists every certificate on the server and the names it covers, which is a quick way to confirm the change.
Wildcards need the DNS challenge
Let's Encrypt only issues wildcard certificates through the DNS-01 challenge, where you prove control by adding a TXT record at _acme-challenge.example.com. Use a Certbot DNS plugin for your DNS provider so renewals are automatic; a manual TXT record works once but will not renew on its own.
sudo certbot certonly --dns-cloudflare \
--dns-cloudflare-credentials /root/.secrets/cloudflare.ini \
-d example.com -d "*.example.com"
Making the server send the right certificate
Most servers host several sites on one IP address and pick the certificate using SNI, the hostname the browser sends at the start of the TLS handshake. If no HTTPS site claims that name, the server sends its default certificate, and you get a mismatch even though the right certificate is installed somewhere on the machine.
nginx
The name must appear in server_name inside a block that listens on 443:
server {
listen 443 ssl;
http2 on;
server_name example.com www.example.com;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
}
Run sudo nginx -t and then sudo systemctl reload nginx. On older nginx versions the http2 setting goes on the listen line instead.
Apache
<VirtualHost *:443>
ServerName example.com
ServerAlias www.example.com
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
</VirtualHost>
A common mistake is adding the alias only to the port 80 virtual host. Run sudo apachectl -S to list which virtual host answers each name on port 443.
Plesk, cPanel and Cloudflare
- Plesk. Open the domain, choose SSL/TLS Certificates, and reissue the Let's Encrypt certificate with the www option ticked. Subdomains are separate entries in Plesk and need their own certificate unless you choose the wildcard option.
- cPanel. AutoSSL covers the domain, www and subdomains that resolve to the server. Run AutoSSL again after adding a subdomain, and check the excluded names list.
- Cloudflare. The free Universal SSL certificate covers the bare domain and one level of subdomain. A name like dev.shop.example.com needs an extra edge certificate. Names set to DNS only skip Cloudflare entirely, so your server must hold a valid certificate for them. See Cloudflare redirects for the related redirect settings.
Worked example: www and a shop subdomain
Example Bakery runs example.com on an nginx server with a Let's Encrypt certificate. The main address loads fine, but visitors who type www.example.com see NET::ERR_CERT_COMMON_NAME_INVALID, and a new shop at shop.example.com shows the same error.
- OpenSSL against www.example.com shows
DNS:example.comas the only SAN. The www name was never requested. - OpenSSL against shop.example.com returns a certificate for the hosting company's server name. There is no nginx block with
server_name shop.example.comon port 443, so the default certificate is sent. - DNS for both names points at the same server, so the HTTP-01 challenge can work for both.
- The owner adds a 443 server block for the shop, then runs
certbot --nginx --expand -d example.com -d www.example.com -d shop.example.com. certbot certificatesnow lists all three names, and OpenSSL against each host shows the full SAN list.- Finally the www block is set to return a 301 to https://example.com, so there is one main address, as covered in www canonicalisation.
Total time was about twenty minutes, and the renewal job now covers all three names together.
The fix, step by step
Step 1
Find the exact hostname that fails
Open each address you use in a private window: the bare domain, www, every subdomain and any extra domains that redirect. Note which ones show NET::ERR_CERT_COMMON_NAME_INVALID or a similar warning and which load with a padlock. Write the failing names down exactly as typed. A pattern where only www or only one subdomain fails tells you the certificate is valid but is missing names, which is the most common case and the quickest to fix.
Step 2
Read the SAN list the server sends
Run openssl s_client -connect www.example.com:443 -servername www.example.com and pipe it into openssl x509 -noout -ext subjectAltName. Repeat for each failing name. If the hostname is missing from the list, you need to reissue. If the list shows an unrelated domain such as the server's own name, the server is sending its default certificate because no HTTPS site exists for that hostname. Keep this output to compare after the fix.
Step 3
Check where DNS points each name
Run dig +short for the bare domain, www and each subdomain. Every name you want covered by your server's certificate must resolve to that server, otherwise the HTTP challenge cannot succeed and visitors will never reach your certificate anyway. If a name is a CNAME to a hosted platform or CDN, fix the certificate on that service instead. Correct any stale A records and wait for the old TTL to expire before issuing.
Step 4
Add an HTTPS site for every name
Make sure each hostname is claimed by a site listening on port 443. In nginx add it to server_name in the 443 block; in Apache add a ServerAlias inside the VirtualHost *:443 section. In Plesk or cPanel, create the subdomain or alias in the panel first. Test the configuration with nginx -t or apachectl -S, which also shows which site answers each name, then reload the web server.
Step 5
Reissue the certificate with all names
Request a certificate that lists every name: certbot --nginx --expand -d example.com -d www.example.com -d shop.example.com. For a wildcard, use a Certbot DNS plugin with -d example.com -d *.example.com, quoting the wildcard in your shell. In a hosting panel, reissue Let's Encrypt with the www and subdomain options ticked. Confirm with certbot certificates or the panel's certificate list that the new certificate shows every hostname you wrote down.
Step 6
Attach the certificate to the right site
Point each HTTPS site at the new files: fullchain.pem for the certificate and privkey.pem for the key in nginx or Apache, or select the new certificate in the panel's hosting settings. Certbot's web server plugins do this for you, but manual installs often leave the old certificate in place. Reload the web server, then run the OpenSSL command again for each name and check the SAN list now includes it.
Step 7
Cover CDN and platform hostnames
If a name is proxied through a CDN, check that its edge certificate lists the hostname, and order an extra certificate for names deeper than one subdomain level. If a name is hosted on a site builder or shop platform, add it as a custom domain in that platform and wait for the platform to show the certificate as active. Test again with OpenSSL, because the CDN or platform answers for those names, not your server.
Step 8
Redirect extra names to one address
Once every name has a valid certificate, choose one main address and add 301 redirects from the others, for example www to the bare domain. Use a single hop so there is no chain. Check with curl -I https://www.example.com that the response is a 301 with the right Location header and that the browser shows no warning before the redirect. Update internal links and the sitemap to use the main address only.
Step 9
Test renewal and re-check later
Run certbot renew --dry-run and make sure every name validates, because one broken name can block renewal of the whole certificate. For DNS challenges, confirm the plugin credentials work without manual steps. Add a reminder to re-test all hostnames after any DNS, CDN or hosting change. Run the security audit on each hostname and confirm it reports the certificate as valid for the visited name.
Edge cases worth knowing
- Old domains that only redirect. If example.co.uk redirects to example.com, it still needs its own valid certificate, or HTTPS visitors and crawlers stop at the warning before the redirect is read.
- Hosted platforms. When www is a CNAME to a site builder or shop platform, the platform issues the certificate. Add the custom domain in the platform's settings and wait for it to show as active; installing a certificate on your own server does nothing for that name.
- Mail and panel addresses. mail.example.com, webmail and the control panel address are hostnames too. In Plesk, tick the option to secure webmail when you issue the certificate if you use it.
- HSTS with includeSubDomains. If your main site sends HSTS with
includeSubDomains, every subdomain must have a valid certificate, and browsers will not let visitors click past the warning. See HSTS errors. - Windows servers. IIS needs a binding per hostname with SNI ticked, as described in IIS SSL bindings.
Keeping every hostname covered
Most mismatches come back when someone adds a subdomain or changes DNS months later. Keep a short list of every hostname in use, and whenever you add one, expand the certificate in the same change. Check renewals with sudo certbot renew --dry-run, because one name that no longer points at the server can fail the whole certificate.
Run the hostnames through the security audit after any DNS or hosting change, and test with OpenSSL using -servername for each name, not just the main one. If the site loads with a padlock but still says not secure, the problem has moved on to a certificate that is installed but not working, which is usually mixed content or a missing redirect.
1. How do I fix an SSL certificate with the wrong hostname?
You fix it by issuing a certificate whose Subject Alternative Name list includes the exact hostname, and making sure the server sends that certificate for that name. First check the names the server really sends using OpenSSL with the servername option. If the name is missing, reissue with every hostname listed. If an unrelated certificate appears, create an HTTPS virtual host for the name so the server stops falling back to its default certificate. Reload the web server and test each hostname again before moving on.
2. Why is my SSL certificate not working on a subdomain?
Your SSL certificate is not working on the subdomain because the subdomain is not listed on it, or because the server has no HTTPS site for that subdomain and sends a default certificate instead. A certificate for example.com does not automatically cover shop.example.com. Either expand the existing certificate to include the subdomain, issue a separate certificate for it, or use a wildcard. Also check that the subdomain's DNS points at the server holding the certificate, rather than at an old host or a platform.
3. Does a wildcard certificate cover the main domain?
No, a wildcard certificate for *.example.com does not cover example.com on its own, and it does not cover two levels down such as dev.shop.example.com. The asterisk matches exactly one label. In practice you request the wildcard and the bare domain together on the same certificate, which Let's Encrypt and most paid authorities allow. For deeper subdomains you need either the exact name on the certificate or a second wildcard such as *.shop.example.com, which again needs the DNS challenge.
4. Why does www work without a padlock warning but the bare domain does not?
This happens because the certificate was issued only for www, or because the bare domain points to a different server from www. Some hosts and site builders only secure the www name by default. Check the SAN list for the bare domain with OpenSSL and look at its DNS record. Either add the bare domain to the certificate, or make sure the server or platform that answers for it holds its own valid certificate and then redirects visitors to the www address.
5. Can I just redirect www to the main domain to stop the error?
No, a redirect alone cannot stop the error because the browser checks the certificate during the TLS handshake, before it ever sees the redirect response. If www is not on a valid certificate, visitors get the warning and never reach the redirect. Add www to the certificate first, then set up the 301 redirect. After that, the redirect works for visitors, bookmarks and search engines, and the www name stops showing up as a security problem in audits.
6. What is SNI and why does it cause the wrong certificate to show?
SNI, or Server Name Indication, is the part of the TLS handshake where the browser tells the server which hostname it wants, so one IP address can serve many sites with different certificates. If no HTTPS site on the server is configured for that hostname, the server sends its default certificate, which is for some other name. The fix is to add the hostname to the right HTTPS virtual host, or in IIS to create a binding for that hostname with SNI enabled.
7. How long does it take for a fixed certificate to work?
A fixed certificate works as soon as the web server is reloaded with it, usually within seconds. Browsers do not cache a failed certificate check, so a fresh visit picks up the new certificate straight away. Delays come from elsewhere: DNS changes can take up to the old record's TTL to spread, CDN edge certificates can take a few minutes to deploy, and hosted platforms may take up to a day to issue a certificate for a newly added custom domain.
Run the security audit on each of your hostnames to see the names on the certificate the server sends, its issuer and expiry date, and whether the visited host is covered.
Open Security Audit Fixes โ