Apache ignoring mime-type - apache

I have a page that is using JWPlayer to serve a video in a variety of format choices (mp4, m4v, ogv, webm). However, when accessing the page from Firefox (23.0.1) or with PHP curl, Apache is returning a header indicating the content-type as text/plain. Firefox (and newer IE versions, unless in compatibility mode) will not play the video. I have tried adding the mime types in mime.types, httpd.conf, and in an .htaccess file in the directory.
mime.types
video/mp4 mp4 m4v
video/ogg ogv
video/webm webm
httpd.conf
AddType video/mp4 mp4 m4v
AddType video/ogg ogv
AddType video/webm webm
.htaccess
AddType video/mp4 mp4 m4v
AddType video/ogg ogv
AddType video/webm webm
I have tried with and without the dot in front of the extensions (which as I understand should work either way). I have restarted Apache. I have verified that I am editing the right configuration files. Still Apache continues to return the text/plain type. Where have I gone wrong?
UPDATE: Tried FilesMatch and ForceType directive as suggested by rekire in httpd.conf, virtualhost, and .htaccess. Tried renaming files and changing links to match in case of middleman caching. Going straight to the URL downloads the video and allows to play it in desktop player normally.

In the official documentation for AddType of mod_mime are the file extensions listed with a leading dot so try this:
AddType video/mp4 .mp4 .m4v
AddType video/ogg .ogv
AddType video/webm .webm
Or try ForceType together with FilesMatch:
<FilesMatch "\.(mp4|m4v)$">
ForceType video/mp4
</FilesMatch>

Answering my own question, over 2 years later. It turned out to be an issue that was not determinable from the information I gave in the question, and a relatively simple problem. There was an .htaccess file that was routing ALL requests - existing resource files or not - to a PHP file, which was then handling all file requests itself, including returning a MIME type, effectively bypassing all of the handling I was attempting to do in Apache.

Related

Apache Server - Content-Type HTTP Header

Hi I am having an issue where the client side is unable to connect/play video content from a .mp4 asset file located on an Apache Server.
I am suspecting the issue has to do with the Content-Type parameter in the HTTP Headers.
How can I modify this Content-Type parameter to see if this is the issue?
I'd like to try video/mp4, audio/mp4, audio/m4a, audio/aac, etc.
To fix this issue on Apache you need to add the following content to the ‘.htaccess‘ file which is found in your document root (public_html or htdocs).
just paste this to your .htaccess (required mime types)
AddType video/mp4 mp4 m4v
AddType audio/mp4 m4a
You can also add these mime types directly in the Apache configuration file ‘mime.types’
/etc/httpd/conf/mime.types
add required mime.types.
video/mp4 mp4 m4v
audio/mp4 m4a
then restart apache.

Apache always returning js as text/plain

I have an Apache install which always returns .js files as text/plain.
I've disabled mod_negotioation, and checked the MIME is set in /etc/mime.types. I know this is the correct file, as I added application/font-woff, which is working as expected.
I've also disabled mod_pagespeed, and renamed /etc/apache2/magic to /etc/apache2/magic.disabled, even though mod_mime_magic isn't enabled.
Even adding AddType application/javascript .js to the .htaccess results in the same text/plain.
Where else can I force the type to be set?
Use the other JavaScript mime types:
AddType application/x-javascript .js
#AddType application/x-ecmascript .js
#AddType application/ecmascript .js
#AddType text/javascript .js
#AddType text/ecmascript .js
Try one at a time until you find a match.
References
RFC 4329: Scripting Media Types
Reducing MIME type security risks (Windows)

Firefox error with Video JS

I am getting an error in Firefox (ver 22/23) that says:
Specified "type" attribute of "video/mp4" is not supported. Load of media resource xxxxx failed.
Is this repairable?
It's all about MIME types. When you specify type attribute on your video source - you also need to make sure your server understands what that types of files actually mean.
AddType video/ogg .ogv
AddType video/mp4 .mp4
AddType video/webm .webm
Add these lines to your server's .htaccess file and you'll be up'n'running.
For any additional information related to video conversion/playback - check out this article

htaccess setting the mimetype for a single file

In an .htaccess file one might set the mimetype for a given extension like:
AddType application/javascript .js
How would one set the mimetype for a single file instead of an extension? I have one Javascript that needs a different mimetype than other Javascript files in the same folder.
AddType application/javascript .js
AddType application/ecmascript specialfile.js
The second line does not work.
You can use the <files> container to match the file's name before adding a type for it:
<Files specialfile.js>
AddType application/ecmascript .js
</Files>

Correct Apache AddType directives for font MIME types

I’m using #font-face for embedded fonts (thanks Paul Irish). In trying to fix Chrome’s warning about wrong MIME type for woff fonts, I’ve discovered a mass of conflicting suggestions.
Everyone seems to agree that .eot fonts (for IE 6-8?) should be served using
AddType application/vnd.ms-fontobject .eot
For .ttf fonts (older non-IE browsers?) I’ve seen
AddType application/x-font-ttf .ttf
AddType application/octet-stream .ttf
AddType font/truetype .ttf
AddType font/ttf .ttf
And for .woff fonts (the new standard?) I’ve seen
AddType application/font-wof .woff
AddType application/x-font-woff .woff
AddType application/x-woff .woff
I understand the correct MIME type for woff will be application/font-woff, but until the standard is official, application/x-font-woff is understood by Chrome.
I realise I’ve half answered my question in asking it, but the question is really: is there any authoritative guidance or further advice about what MIME types should be used for fonts?
Update (in case it’s of any help to anyone else): since there seems to be nothing authoritative, I’ve settled on using the following font MIME types in my .htaccess (which at least keeps Chrome happy):
AddType application/vnd.ms-fontobject .eot
AddType application/x-font-ttf .ttf
AddType application/x-font-woff .woff
I realize that this question is old, but for anyone looking for a quick copy/paste for adding font MIME types to their .htaccess:
<IfModule mod_mime.c>
AddType application/vnd.ms-fontobject .eot
AddType application/x-font-opentype .otf
AddType image/svg+xml .svg
AddType application/x-font-ttf .ttf
AddType application/font-woff .woff
AddType application/font-woff2 .woff2
</IfModule>
I just did some research on IANA official list. This appears to be the current state of the play as at May 2013:
These three are official and assigned by IANA:
svg as "image/svg+xml"
woff as "application/font-woff"
eot as "application/vnd.ms-fontobject"
These are not not official/assigned, and so must use the 'x-' syntax:
ttf as "application/x-font-ttf"
otf as "application/x-font-opentype"
It appears that the 'font' type does not exist, so any time type you see 'font/xxx' it is bogus. Possibly 'x-font/xxx' would be allowable, not sure. IIS8 ships with a couple entries like this. Not sure if MS thinks these 'font/xxx' ones are needed for compatibility, or if they just don't read RFCs :-)
The application/font-woff appears new and maybe only official since Jan 2013. So "application/x-font-woff" might be safer/more compatible in the short term.
Usually, MIME types come from RFC.
You have a exhaustive list on the IANA site but none refers to the font extensions.
Moreover, document describing WOFF format is draft and does not refer to the mime type to use.
No reliable reference on the subject seems to exist for now.
Update
The W3C has now released WOFF as a recommendation, and in Appendix B defined the MIME type as application/font-woff. It's also been added to the IANA site that you mentioned now. -GKFX
I think it's worth mentioning that, as from March 2013, IANA gave the .otf and .ttf extentions the MIME type of application/font-sfnt.
For a complete and current list of official MIME types, see my answer on Proper MIME type for fonts
in 2019 you can use:
AddType font/otf .otf
AddType font/ttf .ttf
AddType font/woff .woff
AddType font/woff2 .woff2
AddType application/vnd.ms-fontobject .eot
Here a example for caching all font types in apache (tested on Google Page Speed):
AddType application/font-sfnt otf ttf
AddType application/font-woff woff
AddType application/font-woff2 woff2
AddType application/vnd.ms-fontobject eot
ExpiresByType application/font-woff "access plus 1 month"
ExpiresByType application/font-woff2 "access plus 1 month"
ExpiresByType application/font-sfnt "access plus 1 month"
ExpiresByType application/vnd.ms-fontobject "access plus 1 month"