One of the most simple solutions would be to output the specified files using a php script. To do this, you can configure mod_rewrite to redirect requests to the specified file to your script:
RewriteRule ^(script\.js)|(img\.jpg)$ log.php?file=$1 [L]
After that, the request for the specified files will be redirected to the log.php file, and the file name will be specified as the _GET parameter of the file .
In the script itself, you can now perform the necessary logging procedures and give the contents of the file.
<?php $file = $_GET['file']; // записать лог // .... // отдать файл readfile($file);
for the js file, however, you can make it even easier
<?php // логгируем доступ ?> //текст вашего js-файла alert("hello world!");
but perhaps the first option is preferable.
The question will be what and how you will log and receive information from where. Sites from which a request comes to the file can be obtained through the referer , the IP addresses of the users via remote_addr .
In order not to write your own website to the log, you can do the appropriate check in a .htaccess la RewriteCond "%{HTTP_REFERER}" "!www.example.com" [NC] . But then you can just simply deny access to files, if not requested from your site. However, it should be understood that with a direct request to the file these headers will not be.
heaersomething to do with it? You do not need to give the file for downloading, but just output it. - teran