Force video/webm mime type using .htaccess based on request uri

扶醉桌前 提交于 2019-12-05 02:25:42

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

taltu

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

Unable to get this to work in Apache, I gave up and moved to nginx instead. I got it to work in nginx using:

location ~\.webm$ {
  add_header Content-Type video/webm;
  rewrite  (.+?\.fid)/ /$1  break;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!