Custom alternative language pages syntax and hreflang links
« on: September 24, 2021, 12:18:48 AM »
We have the following architecture for our website where we have a tld and we have separate stores using directories for non-us pricing and shipping based on regions.  Each regional site basically has the exact same pages as the us site.
Code: [Select]
www.xyz.com - tld
www.xyz.com/zyx - english/us pricing
www.xyz.com/zyx_ca - english/canadian pricing
www.xyz.com/zyx_eu - english/eu pricing
...

To start with we used these settings for the custom alternative language pages (note the extra forward slash that is required with the wildcard...not sure why but this is what was needed)
Code: [Select]
https://www.xyx.com/zyx//*
en-CA https://www.xyx.com/zyx_ca/

This produced results like the following in the sitemap.xml
Code: [Select]
<url>
  <loc>https://www.xyz.com/zyx/products_category_all</loc>
  <xhtml:link rel="alternate" hreflang="en-CA" href="https://www.xyz.com/zyx_ca/products_category_all" />
</url>
...
<url>
  <loc>https://www.xyz.com/zyx_ca/products_category_all</loc>
</url>

If the custom alternative language pages are updated to what's below you also get the xhtml link for the _ca page as well
Code: [Select]
https://www.xyz.com/zyx//*
en-CA https://www.xyz.com/zyx_ca/
https://www.xyz.com/zyx_ca//*
en https://www.xyz.com/zyx/

However, according to google each link has to have all the other links so the end result needs to be the what is shown below.  Is this possible with the current version?  Also can you explain the need for the extra / in specifying the wildcard url.
Code: [Select]
<url>
  <loc>https://www.xyz.com/zyx/products_category_all</loc>
  <xhtml:link rel="alternate" hreflang="en-CA" href="https://www.xyz.com/zyx_ca/products_category_all" />
  <xhtml:link rel="alternate" hreflang="en" href="https://www.xyz.com/zyx/products_category_all" />
</url>
...
<url>
  <loc>https://www.xyz.com/zyx_ca/products_category_all</loc>
  <xhtml:link rel="alternate" hreflang="en-CA" href="https://www.xyz.com/zyx_ca/products_category_all" />
  <xhtml:link rel="alternate" hreflang="en" href="https://www.xyz.com/zyx/products_category_all" />
</url>
« Last Edit: September 24, 2021, 12:28:21 AM by bob.lewis »
Re: Custom alternative language pages syntax and hreflang links
« Reply #2 on: September 29, 2021, 07:07:43 PM »
Thanks. That works. I thought I had tried a capture group, but probably didn't have the replacement token.  Also figured out how to get the complete hreflang for each corresponding link.  You just have to add an entry for each base url with all the alternate languages under each.

Code: [Select]
https://www.xyz.com/zyx/(.*)
x-default https://www.xyz.com/zyx/$1
en-CA https://www.xyz.com/zyx_ca/$1

https://www.xyz.com/zyx_ca/(.*)
x-default https://www.xyz.com/zyx/$1
en-CA https://www.xyz.com/zyx_ca/$1