put this code in your DOCUMENT_ROOT/.htaccess
file:
RewriteEngine On
RewriteCond %{HTTP_REFERER} google [NC]
RewriteRule ^upload/([^/]+)/([0-9]+)/[^.]+\.jpe?g$ /az/$1/item/$2/ [L,NC,R]
Just keep in mind that HTTP_REFERER
header can be manipulated.