schema.org website gives an example of a breadcrumb represented in JSON-LD
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "BreadcrumbList",
"itemListElement":
[
{
"@type": "ListItem",
"position": 1,
"item":
{
"@id": "https://example.com/dresses",
"name": "Dresses"
}
},
{
"@type": "ListItem",
"position": 2,
"item":
{
"@id": "https://example.com/dresses/real",
"name": "Real Dresses"
}
}
]
}
</script>
大部分内容对我来说都很清楚,但我并不完全确定本例中提供的链接的语义。
令我困惑的是@id
属性。它们的值是URL,看起来这些应该导致由breadcrumb项链接到的实际网页。但是,该属性的名称表明URL实际上可能指向某些本体中的概念标识符。这是什么?
“无标记”选项卡包含一个未注释的HTML,表明我的第一个猜测是正确的,并且URL实际上会导致网页。
<ol>
<li>
<a href="https://example.com/dresses">Dresses</a>
</li>
<li>
<a href="https://example.com/dresses/real">Real Dresses</a>
</li>
</ol>
是这种情况,是否可以在此上下文中使用相对URL?
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "BreadcrumbList",
"itemListElement":
[
{
"@type": "ListItem",
"position": 1,
"item":
{
"@id": "https://dresses.com/dresses",
"name": "Dresses"
}
},
{
"@type": "ListItem",
"position": 2,
"item":
{
"@id": "/dresses/cocktail",
"name": "Cocktail Dresses"
}
}
]
}
</script>
我有同样的问题,并最终做了我在https://webuniverse.io/relative-urls-in-structured-data/上记录的研究。关键部分是:
如果您将标记直接粘贴到Google验证程序中并且存在相对路径 - 验证程序不知道它属于哪个域,只是附加自己的域(https://search.google.com)。一旦部署了更改并使用真实URL进行测试,您将看到验证器将附加正确的域,因此您肯定可以在结构化数据中使用相对URL。
在我看来应该没问题。
检查:https://search.google.com/structured-data/testing-tool
具有相对URL的示例测试数据:
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "BreadcrumbList",
"itemListElement": [{
"@type": "ListItem",
"position": 1,
"item": {
"@id": "http://www.example.com/",
"name": "Home"
}
},{
"@type": "ListItem",
"position": 2,
"item": {
"@id": "/furniture/",
"name": "Furniture"
}
},{
"@type": "ListItem",
"position": 3,
"item": {
"@id": "/furniture/kitchen/",
"name": "Kitchen"
}
}]
}
</script>
更新刚刚再次检查:哦谷歌添加域http://www.example.com/为结构数据测试工具的输出中没有绝对URL的项目。所以丢弃我的消息,我不确定是否支持相对路径,而是使用绝对路径。
所有网址都应该是绝对的。您可以使用官方测试工具https://search.google.com/structured-data/testing-tool/u/0/,它会在相对URL中出错。