【问题标题】:Google indexing cached product images in Magento谷歌在 Magento 中索引缓存的产品图像
【发布时间】:2015-04-29 18:28:10
【问题描述】:
【问题讨论】:
标签:
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