locked
Multilingual dynamic sitemaps RRS feed

  • Question

  • User1738843376 posted

    Hi,

    I have a website that presents pages in 3 distinct languages. 

    This website uses URLRouting, and because of that, the same content in distinct languages might not only change the lang string in the URL, but also the rest of the url, since it is translated to each languages to be more user friendly.

    Ex:
    www.mywebsite/en/contacts
    www.mywebsite/es/contactos
    www.mywebsite/pt/contacte-nos

    www.mywebsite/en/list/news
    www.mywebsite/es/lista/noticias
    www.mywebsite/pt/lista/noticias

    www.mywebsite/en/somecategory/somesubcategory/someproduct
    www.mywebsite/es/unacategoria/unasubcategoria/unproducto
    www.mywebsite/pt/umacategoria/umasubcategoria/umproduto

    In this latest example, "somecategory", "somesubcategory" and "someproduct" vary depending of the data record read from the database. Same applies to the versions of the other languages. As you might expect, the database contains multiple categories, that link to multiple subcategories, which in turn have multiple products. All of these are dynamic, since they can be managed (inserted/updated/deleted) from the website backoffice.

    I'm aware that i can use the <xhtml:_link> node to include alternate URLs for distinct languages, but the model of this node does not seem to be compatible with this form of URLs that i use on the website, since in this model, only 1 parcel of the URL changes, the one related to the language, but the rest remains the same, which is not the case on my website, as you can see from the above examples.

    My question is: how should i be indexing these URLs that follow conventions that go far beyond simply changing the hreflang attribute?

    Is there an alternative?

    I'm currently developing an handler (sitemap.ashx) to serve the XML of the sitemap. Should this handler be generating distinct XMLs according to some parameter for each language instead of writing them all in the same XML? If that is the case, how will Google (and other crawlers) call for the specific language, and how would they know that the language would even exist in the website? I could have the handler receive a querystring to generate the correct version of the XML, but that would imply that the crawlers knew which key/value pair to pass on the handler URL when calling it...

    Please advise

    Tuesday, September 22, 2020 1:26 PM

Answers

  • User1738843376 posted

    Hi yij sun,

    Thanks for the reply!

    I ended up using the example from Google support that i found on:

    https://support.google.com/webmasters/answer/189077?visit_id=637363865636198341-3839018714&rd=1

    I then followed the model they presented for the XML:

    <?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/page.html</loc>
        <xhtml:link 
                   rel="alternate"
                   hreflang="de"
                   href="http://www.example.com/deutsch/page.html"/>
        <xhtml:link 
                   rel="alternate"
                   hreflang="de-ch"
                   href="http://www.example.com/schweiz-deutsch/page.html"/>
        <xhtml:link 
                   rel="alternate"
                   hreflang="en"
                   href="http://www.example.com/english/page.html"/>
      </url>
      <url>
        <loc>http://www.example.com/deutsch/page.html</loc>
        <xhtml:link 
                   rel="alternate"
                   hreflang="de"
                   href="http://www.example.com/deutsch/page.html"/>
        <xhtml:link 
                   rel="alternate"
                   hreflang="de-ch"
                   href="http://www.example.com/schweiz-deutsch/page.html"/>
        <xhtml:link 
                   rel="alternate"
                   hreflang="en"
                   href="http://www.example.com/english/page.html"/>
      </url>
      <url>
        <loc>http://www.example.com/schweiz-deutsch/page.html</loc>
        <xhtml:link 
                   rel="alternate"
                   hreflang="de"
                   href="http://www.example.com/deutsch/page.html"/>
        <xhtml:link 
                   rel="alternate"
                   hreflang="de-ch"
                   href="http://www.example.com/schweiz-deutsch/page.html"/>
        <xhtml:link 
                   rel="alternate"
                   hreflang="en"
                   href="http://www.example.com/english/page.html"/>
      </url>
    </urlset>

    With this model in mind, i created an handler (ashx) to dynamically generate the XML and return it as a stream of XML. It took time and effort, since the website contains a large number of distinct routes.

    In the end, roughly 2000 lines of code end up generating 16000 lines of XML :)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, September 25, 2020 6:38 PM

All replies

  • User1535942433 posted

    Hi 0belix,

    Accroding to your description,could you tell us that do you have write sitemap in the same XML or different XMLs?

    If you write them in the same XML,you could use translating route.Accroding to the language,you could rewrite the rule and index the route rightly.

    By the way,I suggest you could use different XMLs.You could accroding the language to each corresponding xml.

    More details,you could refer to below article:

    https://stackoverflow.com/questions/9436215/how-to-localize-urls-with-routing-in-asp-net-webforms-application-not-mvc

    https://www.4guysfromrolla.com/articles/051309-1.aspx

    Best regards,

    Yijing Sun

    Wednesday, September 23, 2020 8:14 AM
  • User1738843376 posted

    Hi yij sun,

    Thanks for the reply!

    I ended up using the example from Google support that i found on:

    https://support.google.com/webmasters/answer/189077?visit_id=637363865636198341-3839018714&rd=1

    I then followed the model they presented for the XML:

    <?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/page.html</loc>
        <xhtml:link 
                   rel="alternate"
                   hreflang="de"
                   href="http://www.example.com/deutsch/page.html"/>
        <xhtml:link 
                   rel="alternate"
                   hreflang="de-ch"
                   href="http://www.example.com/schweiz-deutsch/page.html"/>
        <xhtml:link 
                   rel="alternate"
                   hreflang="en"
                   href="http://www.example.com/english/page.html"/>
      </url>
      <url>
        <loc>http://www.example.com/deutsch/page.html</loc>
        <xhtml:link 
                   rel="alternate"
                   hreflang="de"
                   href="http://www.example.com/deutsch/page.html"/>
        <xhtml:link 
                   rel="alternate"
                   hreflang="de-ch"
                   href="http://www.example.com/schweiz-deutsch/page.html"/>
        <xhtml:link 
                   rel="alternate"
                   hreflang="en"
                   href="http://www.example.com/english/page.html"/>
      </url>
      <url>
        <loc>http://www.example.com/schweiz-deutsch/page.html</loc>
        <xhtml:link 
                   rel="alternate"
                   hreflang="de"
                   href="http://www.example.com/deutsch/page.html"/>
        <xhtml:link 
                   rel="alternate"
                   hreflang="de-ch"
                   href="http://www.example.com/schweiz-deutsch/page.html"/>
        <xhtml:link 
                   rel="alternate"
                   hreflang="en"
                   href="http://www.example.com/english/page.html"/>
      </url>
    </urlset>

    With this model in mind, i created an handler (ashx) to dynamically generate the XML and return it as a stream of XML. It took time and effort, since the website contains a large number of distinct routes.

    In the end, roughly 2000 lines of code end up generating 16000 lines of XML :)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, September 25, 2020 6:38 PM
  • User1535942433 posted

    Hi 0belix,

    Do you have solved your problems?If you also have problems,you could post to us.Or you could mark these answers which are helpful to you.

    Best regards,

    Yijing Sun

    Wednesday, September 30, 2020 9:38 AM