• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 310
  • 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:


it will call


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?
  • 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.
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.
FourMatAuthor Commented:

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.
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 

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

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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