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

Posted on 2012-09-18
Last Modified: 2012-10-02
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?
Question by:FourMat
    LVL 107

    Expert Comment

    by:Ray Paseur
    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.
    LVL 26

    Expert Comment

    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.

    Author Comment


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

    Accepted Solution

    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


    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    These days socially coordinated efforts have turned into a critical requirement for enterprises.
    Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
    The viewer will learn how to count occurrences of each item in an array.
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now