I have deployed my Hugo website two weeks ago using Netlify. I have bought a custom domain lets call it "xyz.com". I have set up my hosting provider to work with both www.xyz.com and xyz.com (www.xyz.com is the primary domain .i.e. all requests get redirected to www.xyz.com). In my hugo.toml, I have set the base URL to "https://xyz.com/".
The website has no issues, but Google Search Engine has indexed only like 5-6 web pages having the www subdomain and the pages without the www subdomain have not been indexed. Am I doing something wrong here? should I change the base URL? I don’t understand. Why is Google mixing up www and non-www.
Also, I checked the sitemap.xml created by Hugo, All the links are non-www. I have submitted the sitemap to Google Search Console, but Instead of indexing the non-www URLS, my www URLs are indexed (that too not all the pages).
Your netlify got set WWW as a primary domain. The bare domain shall be default and www only alias. This is why when you set in Hugo bare domain Netlify is changing and mixing with WWW
I find ‘www’ preferable from an uptime point of view, as you can set a dynamic CNAME on a ‘www’ subdomain, whereas you have to set a static A record on the ‘naked’ domain.