You can even only redirect to the server without rewriting, but you can face blockages with the Referer:
or difficulties with using the canvas images for example, because of CORS.
The recommended is to use a webproxy (using CURL for example) combined with Apache (if you happen to use technologies canvas
, 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 don’t use Curl very much, it may be that something is missing, let me know if something fails
Did you make it? The report I gave helped?
– RBoschini