Secure WWW and Non-WWW Domains with SSL
example.com and www.example.com as names, make both resolve in DNS, install the certificate on both virtual hosts, and 301 redirect one form to the other. A wildcard is not needed for this.Why both names matter
The apex (example.com) and www are different hostnames. A certificate issued for one does not cover the other unless both are listed in the Subject Alternative Names. People type either form and links in the wild use both, so each must present a valid certificate before it can redirect.
Step 1: DNS for both names
| Record | Name | Value |
|---|---|---|
| A | @ | Your server IPv4 |
| AAAA | @ | Your server IPv6, only if the server really serves it |
| CNAME or A | www | example.com or the same IP |
Check the result with the DNS Lookup tool. Both names should answer.
Secure www and non www with SSL: one certificate
On TryFreeSSL add both hostnames to the request. With Certbot:
sudo certbot certonly --nginx -d example.com -d www.example.com
After issuance, open the certificate in the SSL/CSR Decoder and confirm that both appear in the SAN list.
Secure www and non www with SSL: redirect one to the other
Pick one, keep it, and use it in canonical tags, the sitemap and internal links. Nginx, with non-www preferred:
server {
listen 80;
server_name example.com www.example.com;
return 301 https://example.com$request_uri;
}
server {
listen 443 ssl;
server_name www.example.com;
ssl_certificate /etc/ssl/example/fullchain.pem;
ssl_certificate_key /etc/ssl/example/privkey.pem;
return 301 https://example.com$request_uri;
}
server {
listen 443 ssl;
server_name example.com;
ssl_certificate /etc/ssl/example/fullchain.pem;
ssl_certificate_key /etc/ssl/example/privkey.pem;
# site config
}
Apache equivalent for the www host:
<VirtualHost *:443>
ServerName www.example.com
SSLEngine on
SSLCertificateFile /etc/ssl/example/cert.pem
SSLCertificateKeyFile /etc/ssl/example/privkey.pem
SSLCertificateChainFile /etc/ssl/example/chain.pem
Redirect permanent / https://example.com/
</VirtualHost>
Pitfalls
- The redirecting host also needs the certificate. Without it the redirect cannot happen over HTTPS.
- A CNAME at the apex is not allowed by DNS rules. Use A or AAAA records, or an ALIAS record if your DNS provider supports it.
- A subdomain such as
blog.example.comis not covered unless listed or covered by a wildcard. - On a CDN, enable the certificate for both hostnames in its settings.
Verify
Test all four variants with the HTTPS Redirect checker. Each should end on the same https URL after one 301. Scan the final host with the SSL Checker.
Cookies and CDN notes
Cookies set for the apex can be shared with www and other subdomains if you set the domain attribute, but host-only cookies cannot. Decide this before you switch the preferred host, since changing it logs users out. With a CDN, set the origin host header correctly and add both names in its certificate settings. Update third-party services such as analytics, search consoles and social profiles to the preferred form.
Related reading: fixing the mismatch between the two names and covering subdomains as well.
Frequently Asked Questions
Do I need a wildcard certificate for www?
No. A standard certificate with two names covers apex and www. A wildcard covers many subdomains, but not the apex on its own unless it is listed as well.
Which is better, www or non-www?
Both work. Choose one and stay consistent. www gives some flexibility with CDNs and cookies, non-www is shorter.
Will switching preference affect SEO?
Done with 301 redirects, canonical tags and an updated sitemap, search engines follow the change. Expect a short period of fluctuation.
Do both names need separate certificates?
No, one certificate can list both.
Do I need two certificates?
No. One certificate can list both names, and most authorities issue it in a single request. Two separate certificates work too but double the renewal work.
Which should be preferred, www or the apex?
Either, as long as one redirects to the other. Pick the form you use in links and marketing, then keep it consistent in canonicals and the sitemap.
Why does the padlock break on one form only?
Because only one name is on the certificate, or only one virtual host has the certificate installed. Check the names, then check each server block.
✅ Post-Installation Verification & SEO Checklist
After applying the steps above, run through this 5-point checklist to prevent browser warnings and protect your Google SEO rankings:
- Verify full CA chain trust and TLS 1.3 support using our Live SSL Checker.
- Scan for Mixed Content HTTP links and check HSTS/CSP headers on Security Headers Checker.
- Enforce a permanent 301 HTTP-to-HTTPS redirect with our HTTPS Redirect Generator.
- Confirm both root and
wwwversions resolve cleanly to one canonical HTTPS URL. - Verify your HTTPS property and
sitemap.xmlinside Google Search Console and Bing Webmaster Tools.