1

According to this Google help document, we can create a sitemap telling Google that we have more than one language. But this requires indicating each URL with different languages every time.

That means if you have one URL and three languages, you need to specify a <url> element with a <loc> tag and multiple <xhtml:link> subelements.

If you have twenty URLs and fifteen languages, you would then need ten <url> elements with 20*15^2 <xhtml:link> subelements. That equates to 4500 <xhtml:link> in the same sitemap.xml file, which is a lot!

For Example:

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
  xmlns:xhtml="http://www.w3.org/1999/xhtml">
  <url>
    <loc>http://www.example.com/english/</loc>
    <xhtml:link 
                 rel="alternate"
                 hreflang="de"
                 href="http://www.example.com/deutsch/"
                 />
    <xhtml:link 
                 rel="alternate"
                 hreflang="de-ch"
                 href="http://www.example.com/schweiz-deutsch/"
                 />
    <xhtml:link 
                 rel="alternate"
                 hreflang="en"
                 href="http://www.example.com/english/"
                 />
  </url>

  <url>
    <loc>http://www.example.com/deutsch/</loc>
    <xhtml:link 
                 rel="alternate"
                 hreflang="en"
                 href="http://www.example.com/english/"
                 />
     <xhtml:link 
                 rel="alternate"
                 hreflang="de-ch"
                 href="http://www.example.com/schweiz-deutsch/"
                 />
     <xhtml:link 
                 rel="alternate"
                 hreflang="de"
                 href="http://www.example.com/deutsch/"
                 />
  </url>

  <url>
    <loc>http://www.example.com/schweiz-deutsch/</loc>
     <xhtml:link 
                 rel="alternate"
                 hreflang="de"
                 href="http://www.example.com/deutsch/"
                 />
     <xhtml:link 
                 rel="alternate"
                 hreflang="en"
                 href="http://www.example.com/english/"
                 />
<xhtml:link 
                 rel="alternate"
                 hreflang="de-ch"
                 href="http://www.example.com/schweiz-deutsch/"
                 />
  </url>

</urlset>

Is there a better practice for this?

0

I'd like to increase compatibility of my sitemaps to as many search engines as possible. For this reason, I'd like to only insert my URLs between <loc> and </loc> only. For example:

<loc>http://www.example.com/english/</loc>
<loc>http://www.example.com/french/</loc>
<loc>http://www.example.com/german/</loc>

Also, I'd define the language when each URL is accessed in the following ways:

  1. Using the content-language HTTP header. For example: Content-Language: da

  2. adding the lang attribute to the HTML tag. For example: <html lang="da">

There is also an accept language header that tells you what languages the client (including google) accepts when scanning your page if the client specifies any. That way you won't have google index pages in languages it does not support.

Here's more info on the HTTP headers:

https://en.wikipedia.org/wiki/List_of_HTTP_header_fields

Here's more info on the attributes that can be applied to the HTML tag:

http://www.w3schools.com/tags/ref_language_codes.asp

  • The OP wants to use the ahref lang tags, neither of these options will work for that. – Max Sep 17 '15 at 9:39
1

No this is the only way to define ahref lang tags in an xml sitemap.

Rather that defining the ahref lang tags in an xml sitemap file, would it be easier if you defined them in the source code of the page?

e.g

on http://www.example.com/english/ you would have the following tags within the section of the code

<link rel="alternate" http://www.example.com/english/ hreflang="en" />
<link rel="alternate" http://www.example.com/french/ hreflang="fr" />
<link rel="alternate" http://www.example.com/german/ hreflang="de" />

on http://www.example.com/french/ you would have the following tags within the section of the code

<link rel="alternate" http://www.example.com/english/ hreflang="en" />
<link rel="alternate" http://www.example.com/french/ hreflang="fr" />
<link rel="alternate" http://www.example.com/german/ hreflang="de" />

on http://www.example.com/german/ you would have the following tags within the section of the code

<link rel="alternate" http://www.example.com/english/ hreflang="en" />
<link rel="alternate" http://www.example.com/french/ hreflang="fr" />
<link rel="alternate" http://www.example.com/german/ hreflang="de" />

Similar to in the sitemap, you need to add a tag for the page itself and all the other language versions. But depending on your set up, this might be easier than in an xml sitemap?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.