Google Search Console reports sitemap.xml as invalid


#1

I have a production website running, and while adding it in Google Search Console it reports to me that the URL’s are invalid.

Has anyone else run into this?


#2

Mine has been working like a charm for a few Hugo versions now. Can you share more details?


#3

The error messages from Google are pretty vague, but this is what is displayed:


#4

See the guidelines at Requesting Help and post links to your source and site, so we can actually check and see if the sitemap.xml is valid.

Discussion in these forums are specific to Hugo, but you haven’t asked a Hugo question. Please search elsewhere for debugging sitemaps and search engines. If you suspect the sitemap template is incorrect, please say so and provide context.


#5

Discussion in these forums are specific to Hugo, but you haven’t asked a Hugo question. Please search elsewhere for debugging sitemaps and search engines. If you suspect the sitemap template is incorrect, please say so and provide context.

I’m using the default template, that is why I’m asking. Maybe someone else has run into the same problem. I wouldn’t ask otherwise.

Gist for the Hugo produced sitemap.xml:

Production site:
https://proximoconcurso.com.br

Hugo Version:
0.34 on Netlify

Source repo is private


#6

Please state the error reporting your sitemap.xml is invalid. Your screenshot does not include an error, nor refers to the sitemap.

Listen, I get that you think it has to do with the template in Hugo. But you haven’t explained why you think that, except you got some unrelated errors in a sitemap monitoring service. There isn’t anything we can do. To figure this out we need to see what the errors are, as well as see if it changes over time; it is possible some part of the internet had a hiccup and Google didn’t read your sitemap correctly today.

So if you want help, go back and figure these things out, and then let us know where you are stumped.


#7

If the errors outputted by Google said more than:

“There is an error with the URL’s in your sitemap”

I would have gladly tried research more.

But whatever, I’ll research more and if I find a solution I’ll post it here.

The screenshot is from Google Search Console and it is the only information that is outputted when submitting the sitemap.xml for indexing.


#8

Solved

Ok…

As defined in the sitemap.org documentation for :

URL of the page. This URL must begin with the protocol (such as http) and end with a trailing slash, if your web server requires it. This value must be less than 2,048 characters.

This means that you have to set baseURL to your actual website address. This doesn’t seem ideal if you run it locally and for staging and so on. I guess one has to set environment variables for this.

I change this and pushed it to Netlify, resubmitted the sitemap and now it works.


#9

I need to look at this again. @maiki

If I leave baseURL = “/” like this, Hugo/Netlify is able to detect and serve proper URL’s on the front i.e.; root.tld/path/to/content, and Google Search Console approves the sitemap for indexing.

However, if I set baseURL = “https://root.tld”, it sends me to the production site when running locally + asset urls are linked to the production site.

Shouldn’t sitemap.xml also be able to reflect this change so that it produces the correct url according to the https://www.sitemaps.org/protocol.html definition?


#10

The above is not a valid baseURL. It may work in some cases, but the behaviour is in general undefined and unsupported.


#11

Okay,

What is the recommended approach to get the baseURL to change automatically between dev and production?


#12

It is to:

  • Set the production URL in config.toml
  • Use the default localhost URL when running hugo server (dev)
  • If you need some other URL during development, run hugo server -b http://somehost – but then you probably also want to set the --bind flag to the correct network interface.