I want to log access to any files in the /files folder, so I can process it with PHP to generate some statistics.
I don’t want to write a custom PHP handler called via RewriteRule because I don’t want to have to deal with status codes, MIME-types and caching headers, and file locking issues.
I don’t have access to the server configuration, so I can’t use CustomLog (I do have access to .htacess).
I can’t use X-Sendfile because it’s not enabled.
I don’t have access to the access.log.
Looking for an authorative answer.
I’ve tried a great many things and there seems to be no easy solution.
My solution uses the
Locationheader trick proposed by @yes123 but I’ve tweaked it to match my preferences.The links to the files are kept intact, so it’s still:
/files/path/to/my/file.abcI have a
RewriteRule:RewriteRule ^files/(.*) path/to/tracker.php?path=/$1Then in the file I issue a
Locationheader by adding?track=noto the URL and an exception to the earlierRewriteRule:RewriteCond %{QUERY_STRING} !(&|^)track=no(&|$)I’ve added one more optimization. I’ve enabled E-Tags so if the client send an E-Tag header, see if it matches the file and return a
304 Not Modifiedinstead of aLocation.And implementation for
calculate_apache_etagcan be found here: How do you make an etag that matches Apache?etag_withing_rangesolves the issue of comparing against a higher precisionmtimein Apache.Notes on solutions that didn’t work
virtualTest script:
Outputs:
Content-Type: text/htmlreaaaaalllly? 🙁Perhaps PHP5.3’s
header_removefunction can solve this? I haven’t tried.