I've got a PHP page that renders a dynamic image

/scripts/oem-image.php?brand=$1&sku=$2 break;

I'm trying to do a background redirect (keep the original url) from a .jpg link. For instance, if you requested


it would display the image from the following URL but would still show the above URL in the address bar


Here's what I've got in the nginx config. The only problem is that when you try to go to the /media/... link, it attempts to download the file rather than simple displaying it.

location /media/catalog/product/oem-label/ {
  rewrite ^/media/catalog/product/oem-label/(.*)/(.*).jpg$ /scripts/oem-image.php? brand=$1&sku=$2 break;


I'm setting

<?php header("Content-type: image/jpeg"); ?>

and have also tried

<?php header("Content-disposition: inline"); ?>
  • 1
    Are you sure you're sending the right Content-Type and Content-Disposition headers in your application? – Michael Hampton Sep 12 '14 at 23:02
  • 1
    header("Content-type: image/jpeg"); – eisaacson Sep 12 '14 at 23:03
  • If you access /scripts/oem-image.php?brand=honda&sku=3580-hn7-004 directly, does it behave the same? – dartonw Sep 13 '14 at 5:55
  • Accessing it directly shows the image as intended. It does not attempt to download. – eisaacson Sep 15 '14 at 14:49
  • Anyone have any ideas? – eisaacson Sep 16 '14 at 22:11

Try to switch break by last in your redirect

  • Could you provide an example, rather? – eisaacson Oct 28 '14 at 23:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.