Redirect .jpg to .php

This may sound weird but is it possible to redirect from a file.jpg to file.php?

:goof:

Hi Viktor!

Yes, absolutely! You can match any extension in the regex of a RewriteRule and redirect as required. If you do that, however, remember that the PHP script must then send the image headers that would have been sent for the JPG file.

Regards,

DK

Hi David!

according to that : I need to set up a mod_rewrite rule in a .htaccess which ‘says’ redirect ALL visits from mysite.com/images/image1.jpg to mysite.com/products.php ?

Thank you in advance! :slight_smile:

Viktor,

Not quite - it depends upon which images you want to specify and …

Well, to redirect ALL .jpg images to your products.php script (products? Perhaps product_images.php?) you would use RewriteRule \.jpg$ product_images.php [L]. Of course, if it’s only image1.jpg, then you were fine.

Regards,

DK