The root domain and its www hostname are separate DNS names. They can reach the same site, but both must be accepted by the hosting service and covered by HTTPS. Choose one preferred URL and redirect the other consistently.
IN THIS ARTICLE
What you need before you begin
Record existing A, AAAA and CNAME values for both names. Check whether your hosting product expects direct server addresses, a CDN hostname or a custom-domain verification process. Back up existing redirect rules before editing them.
01 Make www and the root domain reach the same website consistently
- Add both names to the intended website or its supported domain-alias configuration. Confirm that they do not belong to different customer sites.
- Point the apex using the service's supported A/AAAA or apex-flattening method. A plain apex CNAME is not a universal solution.
- Configure www using the provider's required CNAME or addresses. Remove only conflicting data at that same owner name after recording the previous values.
- Issue or install a certificate that covers both names. The hostname being redirected also needs valid HTTPS when visitors request it over TLS.
- Set one canonical hostname in the application or hosting redirect control. Test a temporary redirect first, preserving useful paths and query parameters, then make the move permanent when verified.
02 Example: verify both DNS names and the preferred website URL
From your workstation, test the root domain and www separately. Replace example.com with your site. These DNS and HTTPS HEAD checks help distinguish an address problem from a web redirect or certificate problem.
dig example.com A +short
dig www.example.com CNAME +short
curl --head --connect-timeout 10 --max-time 20 https://example.com/
curl --head --connect-timeout 10 --max-time 20 https://www.example.com/
Read the result: If one hostname redirects, examine its Location header and confirm it points to the chosen canonical URL. Both names need suitable HTTPS coverage before a browser can follow an HTTPS redirect. A correct CNAME does not create the redirect or set the application's preferred hostname.
Also compare AAAA records when IPv6 is enabled. Test a normal page with its query string to ensure the redirect preserves the intended path. Remove conflicting redirect rules through the control panel or application that owns them, then test again without relying only on a cached browser result.
Confirm the expected result
Open HTTP and HTTPS versions of both names, including an inner page. Confirm a short redirect path, the intended final URL, valid certificates and working sign-in or checkout.
Troubleshoot unexpected results
Repeated switching between www and the apex usually means the application, CDN and server disagree about the preferred hostname or HTTPS. Align those settings rather than adding another broad redirect rule.
A common question
Does a CNAME from www to the root change the URL shown in a browser?
No. It changes DNS resolution, while the browser still requests the original hostname. A web-server, application or CDN redirect changes the visible URL. Configure the actual website to accept and secure both names.