RewriteEngine On
RewriteRule ^(.*)$ /file.php?q=$1 [NC,L,QSA]
The "file.php" handles authentication and logging of access. after successful authentication , it just sends the same data that was requested.
Also using this in file.php for handling different file types-
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$ext = finfo_file($finfo,$q);
header('Content-Type: '.$ext);