Skip to content

Instantly share code, notes, and snippets.

@nikkow

nikkow/.htaccess Secret

Created June 6, 2016 07:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikkow/272a3dc215c9ecba9b4655bd3d05b03c to your computer and use it in GitHub Desktop.
Save nikkow/272a3dc215c9ecba9b4655bd3d05b03c to your computer and use it in GitHub Desktop.
PHP Proxy
RewriteEngine On
RewriteRule ^(.*)$ proxy.php [L]
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://storage.<region>.cloud.ovh.net/v1/AUTH_<authkey>/<conteneur>". $_SERVER['REQUEST_URI']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_HEADER, true);
$response = curl_exec($ch);
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = explode("\n", substr($response, 0, $header_size));
$body = substr($response, $header_size);
foreach ($header as $key => $r) {
if (stripos($r, ':') !== FALSE) {
list($headername, $headervalue) = explode(":", $r, 2);
if(in_array(strtolower(trim($headername)), array("content-type", "content-length", "etag"))) {
header(trim($r));
}
}
}
$cache_expire = 60*60*24*10;
header("Pragma: public");
header("Cache-Control: maxage=". $cache_expire);
header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $cache_expire).' GMT');
echo $body;
curl_close($ch);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment