example.com and www.example.com are different DNS names and can have different records.
If one works and the other does not:
- Open the authoritative DNS zone.
- Check the root/apex record for
example.com. - Check the separate record for
www.example.com. - Make sure both ultimately point to a web server configured to serve the domain.
- After DNS is correct, configure the preferred website redirect/canonical behavior at the web layer.
A common arrangement is an A/AAAA record at the root and a CNAME for www, but use the values appropriate for the actual hosting environment.