as the majority of you most likely know, we are able to serve images from PHP using constructs such as this:

RewriteRule ^images/([a-zA-Z0-9]+)\.jpg script.php?image=$1

After which in PHP:

header('Content-Type: image/png');
$image=imagecreatefromjpeg($pathComputedSomewhereElse);
imagejpeg($image);

That's dead simple, but that is not my problem - i merely don't wish to confuse you.

My real question is:

How do i, if it's possible, serve such image directly, using PHP simply to fetch image path? I would like Apache to complete the job, not PHP reading through file and outputting data as binary stream. Prototype markup could be the following [same .htaccess]:

header('Content-Type: image/png');
header('Location: '.$pathComputedSomewhereElse);

For those who have mod_xsendfile set up in your Apache, that you can do exactly the thing you need with no client seeing the road they're rerouted to.

header("X-Sendfile: /path/to/your/filename");
header("Content-type: image/jpeg");

Visit a background article here

Alternatively, when the client is permitted to determine the brand new URL, I do not understand why utilizing a 302 header wouldn't work:

header("Location: http://example.com/path/to/your/imagefile.jpg");
die();
header("Content-Type: image/jpeg\n");
header("Content-Transfer-Encoding: binary");
$fp=fopen("images/$image.jpg" , "r");
if ($fp)
fpassthru($fp);

while using gdlib functions with this is overkill :-)

if you do not wish to customize the file you utilize:

header("Content-Type: image/jpeg\n");
header("Content-Transfer-Encoding: binary");
readfile("images/$image.jpg" , "r");

Try..

RewriteRule ^images/([a-zA-Z0-9]+)\.jpg /new/image/directory/$1.jpg [L]

in htaccess

RewriteRule ([^.]+)\.jpg$ script.php?image=$1

$_REQUEST['image'] consists of path without ".digital", add and gather path )