Non-dynamic custom HTTP headers
According to this Mozilla article on Ogg media, media works more seamlessly in the browser with an X-Content-Duration
header, giving the length in seconds of the piece.
Assuming that I have that length stored somewhere (certainly in a database, perhaps also in the filename itself (video-file-name.XXX.ogv
, where XXX
is the time in seconds)), is there any way to form this extra header using only Apache .htaccess
settings? I ask because loading the file into a PHP script seems clumsy, especially when PHP will by default add other headers which disable caching, and won't respond properly to range (part开发者_开发知识库ial content) requests. Yes, a lot of code could be written in PHP to support ETags and range requests, but it seems like overkill to do all that just to add one header, when Apache has all that functionality built in.
This is the domain of mod_cern_meta. It allows statically assigning extra HTTP headers to files.
You could use a cron job, and generate a *.meta file for every video.
I don't have examples, but you should be able to use mod_header to specify HTTP Response headers at the .htaccess level.
Of course, the question of where should I add the header really depends on how you are accessing it. If you are just hitting a static resource for download, adding it via Apache makes sense. However, you mention a DB. If you decide to store those files in a database, then you have some API providing the file, in which case that API implementation should append the header and not offload to apache.
Also, if the dynamic data you are wanting ever requires processing to determine (its not in the filename or etc) then you're already using some code engine to achieve it, just let that add the header.
This is the kind of thing you do with a mod_perl extension, to intercept these requests and add additional headers before allowing Apache to continue handling it.
One purely PHP approach which might work is to have the requests route through PHP using mod_rewrite, add the additional header, but then let Apache handle the rest by using the virtual function.
Alternatively, you could use your database of durations to contruct a static .htaccess file which uses mod_header to insert the correct duration header for each requested file.
精彩评论