You can even just redirect to the server without rewriting, but you may experience locks with Referer:
or difficulties with using canvas images for example, because of CORS .
It is recommended to use a webproxy (using CURL for example) combined with Apache (if it is to use canvas
technologies, many "html5" plugins make use of this).
Assuming the photos are all from a single domain, it would look something like:
<?php
if (empty($_GET['path']) === false) {
echo 'Caminho não definido';
exit;
}
$path = $_GET['path'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://site-externo.com/' . $path);
curl_setopt($ch, CURLOPT_HEADER, false);
//Envia o user agente do navegador atual
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
//Força retornar binario
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
//Pega os dados
$data = curl_exec($ch);
//Fecha o curl
curl_close($ch);
$ch = NULL;
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if($data === false)
{
http_response_code(404);
echo 'Curl error: ' . curl_error($ch);
} elseif ($httpcode !== 200) {
http_response_code($httpcode);
} else {
$finfo = new finfo(FILEINFO_MIME_TYPE);
header('Content-Type: ' . $finfo->buffer($data));
echo $data;
}
And .htaccess should look like this:
RewriteEngine On
RewriteRule "^local/public/(.*)" proxy.php?path=$1
note: I do not use curl much, something might be missing, please let me know if something goes wrong