You can redirect any request with .htaccess. For example:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
will redirect all requests to index.php
, in which you can check if the user wants file.zip
just by looking into $SERVER['REQUEST_URI']
. Then serve him the file you want:
$zip = '/path/to/zip/file/outside/the/web/root.zip';
// set correct headers, so the browser identifies the response as a zip file
header('Content-type: application/zip;');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($zip) . ';');
header('Content-Disposition: attachment; filename="whatever.zip";');
// output the file contents
readfile($zip);