Should my base URL have www or non-www URL?

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).

Could you share how you got set your A record for domain and CNAME record for WWW in DNS, and than how it’s set on Netlify.

Here is my DNS configuration with my domain provider:

My Netlify domain config:

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

So if I want www throughout I just set www domain as my base Hugo URL right?

Yes.
But if it’s main domain, do not set www as main. Www will redirect to main. Nobody like to type www anymore.

Got it thanks a lot!:heart:

1 Like

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.

2 Likes

:+1::+1::+1:

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.