schema.org 中的相对 URL 语义 JSON-LD 中的面包屑

Semantics of relative URLs in schema.org Breadcrumbs in JSON-LD

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,看起来这些应该指向面包屑项链接到的实际网页。但是,属性 的名称表明这些 URL 实际上可能指向某些 ontology 中的概念标识符。是哪个?

Without Markup 选项卡包含一段未注释的 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://search.google.com/structured-data/testing-tool

具有相对 urls 的示例测试数据:

<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>

更新 刚刚再次检查: 哦google在结构数据测试工具的输出中为没有绝对url的项目添加域http://www.example.com/。所以放弃我的消息,我不确定是否支持相对路径,请使用绝对路径。

所有 URL 都应该是绝对的。 您可以使用官方测试工具 https://search.google.com/structured-data/testing-tool/u/0/,它会在相对 URL 中给出错误。

我有同样的问题并最终做了我在 https://sergeyski.com/relative-urls-in-structured-data/ 上记录的研究。关键部分是这样的:

If you paste markup directly into google validator and there is a relative path - validator doesn't know which domain it belongs to and just appends its own domain (https://search.google.com). Once you deploy changes and test with real url you'll see that validator will append correct domain, so you can definitely use relative urls in structured data.

Is this the case and is it okay to use relative URLs in this context?

在 GitLab,我们也对此感到困惑(参见 relevant issue) since Google's Rich Results Test 与相对 URL 的爆炸, 但是 有历史的例子亲戚 URL 在生产中工作。

所以,我们尝试了一下。我们将一些 json+ld 和 URL 的亲戚推到了生产环境中,我们的一位工程师 received an alert that the id field was invalid.

简短回答 - 不可以将相对 URL 用于 json+ld(但可以使用相对 URL 作为标记,请参阅 ) 和 Google 显然需要绝对 URL。如果它现在可以正常工作,则不能保证将来它会。