• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 307
  • Last Modified:

How can I call a static filename and deliver a dynamic response?

I am using a LAMP server to host an ecommerce system.  In that system, I use an dynamic image thumbnailing and modification script to add watermarks to product images.  

Using that ecommerce system, I am also uploading a products feed to Google.  One of the requirements for the feed specification is that the image must have a standard image file extension, such as .jpg, .png, or .gif.

I would like to use the dynamic script to return a watermarked image to Google when it references an image file name.

For instance, if the Google feed is looking for:

imagename.jpg

it will call

imagemagic.php?img=imagename

and deliver the proper watermarked/modified image back to Google for inclusion into the products indexing system.

Is there a was to use a mod_rewrite or other type of technique to make this happen and still make it look like it is delivering the proper image file type?
0
FourMat
Asked:
FourMat
  • 2
1 Solution
 
Ray PaseurCommented:
I would just write the watermarked image into a directory on your file system and send Google the watermarked file.  It won't take an noticeable extra time, and you'll avoid having Google become suspicious of your scripts.
0
 
arober11Commented:
Assuming Google follows redirects, then something along the following lines should do the trick:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule  ([^/]*)\.jpg$   /imagemagic.php?img=imagename   [L]

Open in new window


Remember to check that mod_rewrite is included in the Apache httpd.conf, and that you have an Option FollowSymLinks  in a Directory entry in the file.
0
 
FourMatAuthor Commented:
arober11,

Will this totally cloak the redirect from Google, or will it be detectable as a redirect or just a standard image file?  The feed specification says that the image must be a file and not a redirect, but I didn't know if using the rewrite rule would be considered a redirect.
0
 
arober11Commented:
It will re-direct, sounds like you require a "custom 404 handler", so you'll want something along the following lines in your httpd.conf / .htaccess

<Files ~ "\.(gif|jpe?g|png)$">
     ErrorDocument 404 /imagemagic.php?img=imagename 
</Files>

Open in new window


Note: You may need to tweak your image-magic script to return a suitable HTTP header, to keep Google happy e.g.

header('Content-type: image/jpeg');
header('Location: '.$imagePathAndName);

Open in new window

0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now