【问题标题】:Google indexing cached product images in Magento谷歌在 Magento 中索引缓存的产品图像
【发布时间】:2015-04-29 18:28:10
【问题描述】:

我在我的 Magento 网站上启用了目录图像缓存,并且产品页面上的图像 URL 的格式为 http://www.example.com/media/catalog/product/cache/2/image/9df61e8b45590e35df96d9f179ca0b11/p/r/product-name.jpg

现在 Google Bot 在抓取网站时会在 URL 处索引这些图像。但是,一周后,由于以下几个原因,此图像可能不存在: 1. 目录缓存被清除。 2. 产品图片被更改/覆盖。

发生这种情况时 - 即使图片出现在图片的 Google 搜索结果中,但在点击访问页面或查看图片时 - 不会打开图片,因为它在服务器上不存在。

由于 URL 结构是默认的 Magento 结构,我想知道如何进行更改,以便图像链接在 Google 搜索结果中起作用。

【问题讨论】:

    标签: image magento caching product google-image-search


    【解决方案1】:

    您可以编写自定义 PHP 脚本并自行调整图像大小。

    并将对产品图像的请求重定向到自定义脚本。

    在媒体模板文件中,您可以将图像定义为例如:
    productimage/14432/1/2.jpg(其中 14432 将是 product_id,1 可能是主图像/样本等,2.jpeg 3.jpg 可能负责图像变体,如大小等)

    然后在 .htaccess 中,您可以将所有 productimage URL 重定向到自定义脚本,并在该脚本中解析来自 url 和进程图像的参数(如果需要,可以缓存)

       RewriteCond %{REQUEST_URI} ^/productimage
       RewriteRule .* imgcustomprocessing.php [L]
    

    imgcustomprocessing.php 这样的脚本可能会这样开始(只是一个粗略的想法)

    <?php 
    require_once 'app/Mage.php';
    Mage::app( "default" );
    
    
    $req =  $_SERVER['REQUEST_URI'];
    $req = explode('/',$req);
    $req = array_filter($req);
    $req = array_values($req);
    
    $product_id =$req[1];
    
    $product = Mage::getModel('catalog/product')->load($product_id);
    
    //to get a real image path
    $url =  Mage::getUrl('media') . 'catalog/product' . $product->getImage();
    
    
    // then here load php libraries for image resizing for example http://phpthumb.sourceforge.net/ pass the $url 
    // put here code for re-sizing image/caching and displaying
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-04
      • 1970-01-01
      相关资源
      最近更新 更多