我当前的搜索网址是以下网址:
https://example.com/search/key/seach_word_here
JSON-LD
<script type='application/ld+json'>
[
{
"@context":"http:\/\/schema.org",
"@type":"WebSite",
"@id":"#website",
"url":"https://example.com",
"name":"Example",
"potentialAction":{
"@type":"SearchAction",
"target":"https:https://example.com/search/key/{search_term_string}",
"query-input":"required name=search_term_string"
}
},
{
"@context":"http:\/\/schema.org",
"@type":"Organization",
"url": "https://example.com",
"name": "Example",
"logo":"https://example.com/img/logo.png",
"@id":"#organization",
"sameAs": ["https://www.facebook.com/example"]
}
]
</script>
您会看到我在target
上使用了友好的网址。
我见过人们在URL上使用查询字符串,像这样:
https://example.com/?search={search_term_string}
我没有看到有人在target
上使用友好的URL。不允许吗?
然后在https://developers.google.com/search/docs/data-types/sitelinks-searchbox上说:
通过从结构化数据中复制WebSite.potentialAction.target URL,用测试查询替换search_term_string并在Web浏览器中浏览至该URL,来验证您的搜索引擎实现。例如,如果您的网站是example.com,并且您想测试查询“小猫”,则可以浏览到
https://www.example.com/search/?q={kittens}
。
我测试了此URL https://example.com/search/hey/{search_word_here}
,但未找到404,但是此URL有效:https://example.com/?p=search&tp=key&word={search_word_here}
。
我的问题是:我可以在target
上使用友好的URL吗?而我的代码段中的代码是正确的吗?
答案 0 :(得分:1)
当然,您必须使用可以正常工作的网址 。
Google将在其站点链接搜索框中使用target
URL,以便用户可以在Google的SERP上进行搜索并最终进入您的内部SERP。如果您指定一个指向404页的target
URL,则具有此功能没有任何意义,并且Google不会对您的结果启用它。
如果该网址恰好是友好的(例如,没有查询组件),请so be it。
答案 1 :(得分:1)
同意@unor的上述解决方案,现在回答有关您的代码更正
请检查发布的JSON-LD中的目标网址:-
"target":"https:https://example.com/search/key/{search_term_string}",
删除双https:
如果是JSON-LD,您也无法将名称值映射到/ {search_term_string}
正确的方法总是这样:-
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "WebSite",
"url": "[website url]",
"potentialAction": {
"@type": "SearchAction",
"target": "[website search url]={search_term}",
"query-input": "required name=search_term"
}
}
</script>
微数据:-
<div itemscope itemtype="http://schema.org/WebSite">
<meta itemprop="url" content="[website url]"/>
<form itemprop="potentialAction" itemscope itemtype="http://schema.org/SearchAction">
<meta itemprop="target" content="[website search url]={search_term}"/>
<input itemprop="query-input" type="text" name="search_term">
<input type="submit">
</form>
</div>