If your subdomain is www, you must redirect the root domain to www.
Example:
Cloudflare
Open Cloudflare Dashboard → select your domain
Go to Rules → Overview → Create rule (Redirect Rules)
When incoming requests match
Wildcard pattern
Request URL:
https://example.com/*
Target URL:
https://www.example.com/${1}Status code: 301
Preserve query string: Enabled
Save & Enable
This ensures all root-domain traffic automatically redirects to www.