I have a rewrite rule in .htaccess
RewriteRule (.+?\.fid)/ /$1 [L]
with a request URI like: /123.fid/myfile.webm
How can I force the mime type to: video/webm
using .htaccess including the rule above?
What I have attempted already, to add on TOP of the .htaccess file without success:
AddType video/webm .webm
and
<FilesMatch "\.webm$">
ForceType video/webm
</FilesMatch>
I use apaches mime_magic module to look up mime type of .fid files, but this doesn't apply to webm files. I'm assuming it's the RewriteRule which is causing problems with the file type, and I need to look for webm in the request uri somehow.
If I do: AddType video/webm .fid
the correct mime type is sent - but this breaks any other file format stored in .fid. Using .fid is a design requirement and cannot change.
*Edit:
I also attempted:
RewriteCond %{REQUEST_URI} \.webm$
RewriteRule .* - [T=video/webm]
and
RewriteRule \.webm$ - [T=video/webm]
with the same result. The mime type served is text/plain
. Could this be mime_magic module interfiering?
I also attempted to add: DefaultType video/webm
which works. This is the closest thing to a solution currently, as mime_magic module seems to find the correct mime types to send, but I don't find this to be a particularly elegant solution
*Edit2: AddType video/webm .fid
IS working - how can I conditionally do AddType based on request uri?
You can use the T-flag in a RewriteRule:
RewriteRule someRegEx$ - [T=video/webm]
http://httpd.apache.org/docs/current/rewrite/flags.html#flag_t
It worked for me, when I added the following lines to my .htaccess
file:
<IfModule mod_rewrite.c>
AddType video/ogg .ogv
AddType video/webm .webm
AddType video/mp4 .mp4
</IfModule>
If you are sending the data with a script (not real files) then the script must send the correct headers, for example with PHP (before any other output):
header("Content-type: video/webm");
In case of real files you can use content-negotiation (instead of rewrite) and:
AddType video/webm .fid
Edit:
Unfortunately I'm not near apache, but this might worth a try:
RewriteCond %{REQUEST_URI} \.webm$
RewriteRule (.*) $1 [E=is_webm:true]
Header set Content-Type video/webm env=is_webm
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With