Magento 避免条件 Google 抓取

Magento Avoide Conditional Google Crawling

根据某些产品属性,我们如何告诉 Google,而不是在 Magento 中索引产品详细信息页面 1.X

您可以尝试监听 "controller_action_layout_generate_blocks_after" 的观察者方法,并从

中获得启发
Mage_ConfigurableSwatches_Model_Observer::convertLayerBlock

然后您可以在观察者方法中执行以下操作:

$front = Mage::app()->getRequest()->getRouteName();
$controller = Mage::app()->getRequest()->getControllerName();
$action = Mage::app()->getRequest()->getActionName();

if ($front == 'catalog' && $controller == 'product' && $action == 'view') {
    $product = Mage::registry('current_product'); 
    if ($product && $product->getYourAttributeName() === "YourDesiredValue") {
        $observer->getLayout()->getBlock('head')->setRobots('NOINDEX,NOFOLLOW');
    }
}