Shopify特定页面精准设置noindex:替代contains与handle规范问询
Shopify精准设置特定页面noindex的解决方案
一、能否用精准匹配替代contains?
完全可以。在Shopify的Liquid模板语言中,使用**双等号==**做精准相等判断,就能避免contains带来的误匹配问题——只有当目标字符串与handle完全一致时,才会触发noindex规则,不会误命中包含关键词的其他页面(比如/collections/all-supplements)。
二、Shopify中handle的规范格式
Shopify的handle有明确规则:
- 所有
handle不带开头的斜杠/ - 多段路径的
handle用斜杠分隔层级,比如/collections/all对应的handle是collections/all,/collections对应的handle是collections - 单个集合的
handle是路径最后一段,比如/collections/all的集合handle是all,但要匹配整个页面路径对应的handle,需写完整的collections/all
三、精准设置noindex的代码示例
针对默认的/collections和/collections/all页面,用handle精准匹配的代码如下:
{% if handle == 'collections' or handle == 'collections/all' %} <meta name="robots" content="noindex"> {% endif %}
如果担心页面类型导致handle判断偏差,也可以直接匹配完整请求路径,更稳妥:
{% if request.path == '/collections' or request.path == '/collections/all' %} <meta name="robots" content="noindex"> {% endif %}
内容的提问来源于stack exchange,提问作者KaraSEO
相关产品推荐
相关产品推荐

