I want to add a few urls to a sitemap that are targeted for a specific location only, but I cannot figure out how to do this.
There’s a great deal of documentation about how to add location specific alternatives to the sitemap (with hreflang), but I cannot find any resources on how to add pages for a specific location only. My initial thought was to just omit the <loc>
value and only specify the <xhtml:link rel="alternate">
tags, but according to the specification <loc>
is required.
So, what is the proper way to add location specific urls to a asitemap?
2
Answers
Remark 1
Please note that there are other search engines than Google which accept sitemaps. The
xmlns:xhtml
namespace which is needed for thehreflang
attribute in sitemaps is a sitemap extension which might not be accepted by all search engines. The sitemap specification does not mention that attribute. Therefore, I wouldn’t use it anyway.Remark 2
In your question, you are using the terms
location
andlanguage
. I am not sure what exactly you mean bylocation
. But please note that there is a difference between a language to be targeted, a certain locale of a language to be targeted and the region to be targeted (which might have nothing to do with the language or locale).This subject is slightly off-topic, so I won’t give a lengthy citation here. The section “Supported language values” from the page I have linked below has some information about it.
Possible solution
Even if you care only about Google, you just might not be able to do what you want – at a first glance, I as well couldn’t find any direct answer to your question.
But fortunately, you don’t need to stuff that kind of meta information into sitemaps. Instead, you can add it to the
<head>
of your HTML files. From this document (emphasis mine):So it is clear that a page not only can, but even should contain a
rel="alternate" hreflang="<insert uri of page itself here>"
link.This might be worrying because no reasonable person would call a certain, given page an alternative to that same page; on the other hand, it makes sense and simplifies things if all of those
<link>
entries have the same form. That way, you could insert exactly the same bunch of<link>
s into every page (e.g. by copy-and-paste or by letting it do some tool or script).The key point here is that this works whether or not a page has something a reasonable person could call an “alternate”. If it hasn’t, the page is the only “alternate” of itself, so just add the one, appropriate
<link>
to its<head>
.Now, coming back to your problem, you could
– remove all
xhtml:link
elements and thexmlns:xhtml
namespace from the sitemap– in every page, add exactly the
hreflang
links which are needed; notably, in every page which only should target one language, just add one link (with the appropriatehreflang
attribute) which references that page itself.Very unsafe reasoning
If you still would like to solve your problem just using sitemap files, you eventually could conclude (by analogy) that including just one alternate link per
<loc>
will produce the same results as if you would have that<link>
in the respective page’s<head>
.IMHO, this conclusion is dangerous, and I have absolutely no clue if it is valid. But you could try it with one new test page which won’t disturb your production web site and see how it works.
I wouldn’t go that way for the reasons mentioned above, though.
Short Answer: Yes. It is possible to add few urls/
<loc>
that are targeted ONLY for a specific geographic location.How?
Create a locale specific entry including a single alternate for the locale itself. I.e. instead of the usual:
Do:
This seems to be enough for Google to infer that the page is only intended for de-ch users and doesn’t have an alternative representation in any other language.
It is also possible to indicate to google that your website(all urls) are for a particular country via GeoTargeting
References: