从搜索引擎隐藏Magento的分层导航 [英] Hiding Magento's Layered Navigation from Search Engines

查看:82
本文介绍了从搜索引擎隐藏Magento的分层导航的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望有人可以帮助我解决过去几天来一直在尝试解决的问题.我想将Magento的分层导航完全从搜索引擎中隐藏,但对用户开放.出于SEO的原因,我不想为NoFollowing所有链接,使用noindex Follow meta标签或什至完全用Robots.txt阻止它而感到不满意.解决此问题的最有效方法是仅向启用了Cookie的用户显示分层导航,因为Google不使用Cookie.使用JavaScript也可能达到相同的效果,但是我选择了Cookie方法.

I’m hoping someone can help me with this problem I’ve been trying to solve for the past few days. I want to hide Magento’s Layered Navigation from the search engines entirely, but make it available to users. For SEO reasons, I don’t want to settle for NoFollowing all the links, or using noindex follow meta tags, or even blocking it entirely with Robots.txt. The most effective way of handling this would be only showing the layered Navigation to users with Cookies enabled, since Google doesn’t use cookies. The same effect could probably be achieved with JavaScript as well, but I’ve chosen the Cookie method.

到目前为止,我已经成功实现了一个粗略的JS,以检查页面加载后(从本论坛的另一个线程改编而成)是否启用了cookie.如果启用了cookie,则不执行任何操作,并显示分层的导航,但是,如果未启用cookie,我想删除"catalog.leftnav"块.我一生都无法从JS脚本中找出解决方法.我所能实现的就是删除div元素,或将style.display设置为none等.尽管所有这些技术都删除了前端的链接,但Google仍然可以看到所有链接.这是到目前为止我在template/catalog/layer/filter.phtml

So far I’ve managed to implement a crude piece of JS to check if cookies are enabled once the page has loaded (adapted from another thread on this forum). If cookies are enabled, it does nothing and layered nav displays, but if cookies are not enabled, I want to remove the "catalog.leftnav" block. I can’t for the life of me figure out how to do this from my JS script. All I’ve been able to achieve is removing the div element, or setting style.display to none etc., and while all of these techniques remove the links from the frontend, Google can still see them all. Here’s an example of the code I have so far in template/catalog/layer/filter.phtml

<div id="shop-by-filters">
  <ol>
    <?php foreach ($this->getItems() as $_item): ?>
    <li>
    <?php if ($_item->getCount() > 0): ?>
    <a href="<?php echo $this->urlEscape($_item->getUrl()) ?>" rel="nofollow"><?php echo $_item->getLabel() ?></a>
    <?php else: echo $_item->getLabel() ?>
    <?php endif; ?>
    <?php if ($this->shouldDisplayProductCount()): ?>
    (<?php echo $_item->getCount() ?>)
    <?php endif; ?>
    </li>
    <?php endforeach ?>
  </ol>
</div>

<script type="text/javascript">
if (navigator.cookieEnabled) {
    return true; 
} else if (navigator.cookieEnabled === undefined) {
    document.cookie = "testcookie";
    if (cookie_present("testcookie"))
        return true;   
} else {
var elem = document.getElementById('shop-by-filters');
elem.parentNode.removeChild(elem);
}
</script>

有人可以帮我这个忙吗,还是有更好的解决方法?请记住,我仍在努力了解Magento,因此,如果实现复杂,我可能需要一些说明.

Can anyone help me with this, or is there a better way of going about it? Please keep in mind that I am still trying to get my head around Magento, so I might need some instructions if the implementation is complicated.

谢谢.

布伦登

推荐答案

以防万一还是有人发现了这个老问题:

Just in case someone still finds this old question:

基于Session/Cookie/User-Agent隐藏(或尝试这样做)来自Google的东西从来都不是一个好主意. Google不喜欢被骗,但希望像其他访客一样看到该网站.

Hiding something from Google (or trying to do so) based on Session/Cookie/User-Agent is never a good idea. Google does not like to be cheated but wants to see the site just like any other visitor.

robots.txt,rel = nofollow等也无法完全解决此问题,或者至少存在一些缺点或限制.

robots.txt, rel=nofollow etc. also do not fully fix this issue or have at least some downsides or limitations.

一种更好,更优雅的解决方案,可以使用 PRG模式.

A better and more elegant solution for hiding layered navigation for crawlers and fix SEO issues caused by the huge number of layered navigation URLs would be using PRG Pattern.

这就像一种魅力,我. e.不会更改关于分层导航的UX,并且在防止爬网程序将爬网预算浪费在无用的重复内容URL上具有100%的可靠性.

This works like a charm, i. e. not changing the UX regarding Layered Navigation and 100% reliable in terms of preventing crawlers from wasting crawl budget on useless duplicate content URLs.

简单地说,这是在将用户重定向到原始分层导航/过滤器URL之前,将GET请求替换为POST请求(搜索引擎爬虫不会遵循的分层请求)到分层导航/过滤器URL.

Simply said, it's about replacing the GET request to a layered navigation/filter URL with a POST request (which search engine crawlers do not follow) before redirecting the user to the original layered navigation/filter URL.

有关更多详细信息和阅读,请参阅

For further details and reading, please see

  1. 为什么robots.txt, rel = nofollow等不是令人满意的解决方案
  2. PRG模式Magento 2扩展名
  3. PRG模式演示
  1. Detailed explanation incl. sample request flow
  2. Why robots.txt, rel=nofollow etc. are no satisfying solutions here
  3. PRG Pattern Magento 2 Extension
  4. PRG Pattern Demo

这篇关于从搜索引擎隐藏Magento的分层导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆