http://ec2.images-amazon.com/images/P/4822245772.01.MZZZZZZZ.jpg
http://ec2.images-amazon.com/images/I/311qdsd1JaL._AA140_.jpg
(※あくまで「雛形」なので、セキュリティとかエラー処理とかはご自分でどうぞ。)#!/usr/bin/perl use strict; use warnings; use CGI; use LWP::Simple; my $q = new CGI; my $asin = $q->param('a'); my $size = $q->param('s') || "s"; my $aurl = "http://webservices.amazon.co.jp/onca/xml?". "Service=AWSECommerceService&". "AWSAccessKeyId=[キー]&". "Operation=ItemLookup&ItemId=$asin&ResponseGroup=Images"; my $res = get($aurl); my $url = ""; if ($size eq "s") { ($url) = $res =~ /<SmallImage><URL>(.+?)</; } elsif ($size eq "m") { ($url) = $res =~ /<MediumImage><URL>(.+?)</; } elsif ($size eq "l") { ($url) = $res =~ /<LargeImage><URL>(.+?)</; } $url = "http://...1x1.jpg(1x1画像のURL)" unless $url; print qq(Location: $url\n\n);
そして、「.htaccess」に下記のように書きます。... $url = "http://...1x1.jpg(1x1画像のURL)" unless $url; my $cache_dir = "/home/hoge/www/foobar/img"; if (-d $cache_dir) { mirror($url, "$cache_dir/$asin-$size.jpg"); } print qq(Location: $url\n\n);
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^img/([A-Z0-9]+)-([sml])\.jpg$ /amaimg.cgi?a=$1&s=$2 [L]