Mapping filename extensions to MIME types
This note describes how to map filename extensions to MIME-types to declare which filename extensions are used by the server and what their inner contents contain.
Mapping filename extensions to content-types is a required part of server configuration. Industry-wide best practices for filename extensions are a good start, but there are too many possibilities to cover every scenario. Consider, by way of example,
simple.svg — only a site's webmaster would know for sure what is in these files and how to serve them. When configuring the server, the
content-types section is used to associate filename extensions with
content-type HTTP headers.
File formats are identified using media-types, also known as MIME types or content-types. These are described in IETF RFC 6838 Media Type Specifications and Registration Procedures.
content-types configuration section is used to associate filename extensions to content-types. It comprises a collection of two-part entries: the left hand side is the filename extension (without a leading dot), and the right-hand side is the MIME-type. Filename extensions are case-sensitive.
When a requested file is found on the server, but no
content-type is associated with its extension, no
content-type header is sent with the response, per HTTP official guidelines.
It is possible that more than one filename extension is used for the same MIME-type. When this occurs, each filename extension should be declared and mapped as a separate configuration entity.
content-types section may appear in either the
server section or a
host section. When values occur in both the
host sections, they are merged according to the standard rules defined for the
|media-type||::=||'text' | 'application' | 'image' | 'audio' | 'video' | 'multipart'|
|subtype||::=||(ALPHA | DIGIT | †)*|
|MIME-type||::=||media-type SOLIDUS subtype|
|filename-extension||::=||(ALPHA | DIGIT | ††)*|
|content-type-entry||::=||filename-extension SP MIME-type CR|
|content-types-section||::=||'content-types' SP LEFT-CURLY-BRACKET CR|
† See section 4.2 of RFC 6838 for exact rules
†† Legal file system characters vary by platform
Example 1: Filename extensions associated with MIME-types
Example 2: Multiple filename extensions with the same MIME-type
Key points to remember:
content-typessection associates filename extensions to MIME-types.
content-typeresponse header will be omitted for any undeclared filename extension.