生成多种语言的站点地图:
按照 Google 的指示:
https://support.google.com/webmasters/answer/189077?hl=en
此代码:
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
<url>
<loc>https://www.example.com</loc>
<lastmod>${formattedDate}</lastmod>
<changefreq>daily</changefreq>
<priority>1.0</priority>
</url>
</urlset>
Run Code Online (Sandbox Code Playgroud)
结果(在浏览器中呈现):
此代码(带有xhtml:link标签):
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
<url>
<loc>https://www.example.com</loc>
<lastmod>${formattedDate}</lastmod>
<changefreq>daily</changefreq>
<priority>1.0</priority>
<xhtml:link rel="alternate" hreflang="en-us" href="https://www.example.com"/>
<xhtml:link rel="alternate" hreflang="en-ca" href="https://ca.example.com"/>
<xhtml:link rel="alternate" hreflang="en-gb" href="https://uk.example.com"/>
</url>
</urlset>
Run Code Online (Sandbox Code Playgroud)
结果(在浏览器中呈现):
问题
似乎没有任何错误。但奇怪的是它没有像往常一样在浏览器中呈现 XML“页面”。
来自 Google的 https://www.google.com/gmail/sitemap.xml似乎也具有相同的行为(您可以检查它并看到响应包含一堆xhtml:link标签)。
我做错了什么还是添加这些标签时的正常行为xhtml:link?
我一直都明白,因为没有en-EUIETF 标签,所以要以欧洲为目标,我必须为欧洲内的每个国家/地区使用en或列出一个hreflang。
查看Think With Google的来源,我注意到以下几点:
<link rel="alternate" href="//thinkwithgoogle.com/intl/es-419/" hreflang="es-419" />
Run Code Online (Sandbox Code Playgroud)
它似乎使用联合国 M.49 代码来表示拉丁美洲和加勒比地区的西班牙语。
在联合国M.49维基百科页面还列出了欧洲码- 150。
我是否可以使用以下hreflang标签来表示欧洲市场的英语?
<link rel="alternate" href="//example.com/intl/en-150/" hreflang="en-150" />
Run Code Online (Sandbox Code Playgroud)