Reputation: 654
I have enabled catalog images caching on my Magento website and the image URL's on the product page are of the form http://www.example.com/media/catalog/product/cache/2/image/9df61e8b45590e35df96d9f179ca0b11/p/r/product-name.jpg
Now Google Bot on crawling the website indexes these images at the URL. However, after one week this image might not exist because of several reasons like: 1. Catalog Cache was cleared. 2. Product Image was changed/overwritten with.
When this happens - even though the images appear in Google search results of images yet, on clicking visit page or see image - no image opens since it does not exist on the server.
Since the URL structure is default Magento structure I want to know how to make changes so that the image links work in the Google search results.
Upvotes: 4
Views: 1077
Reputation: 20611
You can write a custom PHP script and resize images on your own.
and redirect requests for product images to custom script.
In media template files then you can define images for example as:
productimage/14432/1/2.jpg ( where 14432 will be product_id, 1 could be main image/swatch etc, and 2.jpeg 3.jpg may be responsible for image variant like size etc )
then in .htaccess you can redirect all productimage URLs to custom script and inside that script parse parameters from url and process image ( cache if you need )
RewriteCond %{REQUEST_URI} ^/productimage
RewriteRule .* imgcustomprocessing.php [L]
imgcustomprocessing.php such script may start like this (just a rough idea )
<?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
Upvotes: 0