This module provides for determining the types of files from the filename and for association of handlers with files.
Status: Base
Source File: mod_mime.c
The directives AddCharset, AddEncoding, AddHandler, AddLanguage and AddType are all used to map file extensions onto the meta-information for that file. Respectively they set the character set, content-encoding, handler, content-language, and MIME-type (content-type) of documents. The directive TypesConfig is used to specify a file which also maps extensions onto MIME types. The directives ForceType and SetHandler are used to associated all the files in a given location (e.g., a particular directory) onto a particular MIME type or handler.
Note that changing the type or encoding of a file does not
change the value of the Last-Modified
header.
Thus, previously cached copies may still be used by a client or
proxy, with the previous headers.
See also: MimeMagicFile.
Files can have more than one extension, and the order of the
extensions is normally irrelevant. For example, if the
file welcome.html.fr
maps onto content type
text/html
and language French then the file
welcome.fr.html
will map onto exactly the same information.
If more than one extension is given which maps onto the same
type of meta-information, then the one to the right will be
used, except for languages and content encodings. For example, if
.gif
maps to the MIME-type image/gif
and
.html
maps to the MIME-type text/html
, then the
file welcome.gif.html
will be associated with the MIME-type
text/html
.
Languages and content encodings are treated accumulative, because one
can assign more than one language or encoding to a particular resource.
For example, the file welcome.html.en.de
will be delivered
with Content-Language: en, de
and Content-Type:
text/html
.
Care should be taken when a file with multiple extensions
gets associated with both a MIME-type and a handler. This will
usually result in the request being by the module associated
with the handler. For example, if the .imap
extension is mapped to the handler "imap-file" (from mod_imap)
and the .html
extension is mapped to the MIME-type
"text/html", then the file world.imap.html
will be
associated with both the "imap-file" handler and "text/html"
MIME-type. When it is processed, the "imap-file" handler will
be used, and so it will be treated as a mod_imap imagemap
file.
The AddCharset directive maps the given filename extensions to the specified content charset. charset is the MIME charset parameter of filenames containing extension. This mapping is added to any already in force, overriding any mappings that already exist for the same extension.
Example:
AddLanguage ja .ja AddCharset EUC-JP .euc AddCharset ISO-2022-JP .jis AddCharset SHIFT_JIS .sjis
Then the document xxxx.ja.jis
will be treated
as being a Japanese document whose charset is ISO-2022-JP (as
will the document xxxx.jis.ja
). The AddCharset
directive is useful for both to inform the client about the
character encoding of the document so that the document can be
interpreted and displayed appropriately, and for content negotiation,
where the server returns one from several documents based on
the client's charset preference.
The extension argument is case-insensitive, and can be specified with or without a leading dot.
See also: mod_negotiation
The AddEncoding directive maps the given filename extensions to the specified encoding type. MIME-enc is the MIME encoding to use for documents containing the extension. This mapping is added to any already in force, overriding any mappings that already exist for the same extension. Example:
AddEncoding x-gzip .gz
AddEncoding x-compress .Z
This will cause filenames containing the .gz extension to be
marked as encoded using the x-gzip encoding, and filenames
containing the .Z extension to be marked as encoded with
x-compress.
Old clients expect x-gzip
and
x-compress
, however the standard dictates that
they're equivalent to gzip
and
compress
respectively. Apache does content
encoding comparisons by ignoring any leading x-
.
When responding with an encoding Apache will use whatever form
(i.e., x-foo
or foo
) the
client requested. If the client didn't specifically request a
particular form Apache will use the form given by the
AddEncoding
directive. To make this long story
short, you should always use x-gzip
and
x-compress
for these two specific encodings. More
recent encodings, such as deflate
should be
specified without the x-
.
The extension argument is case-insensitive, and can be specified with or without a leading dot.
See also: Files with multiple extensions
AddHandler maps the filename extensions extension
to the handler
handler-name. This mapping is added to any already in
force, overriding any mappings that already exist for the same
extension. For example, to activate CGI scripts with
the file extension ".cgi
", you might use:
AddHandler cgi-script .cgi
Once that has been put into your srm.conf or httpd.conf
file, any file containing the ".cgi
" extension
will be treated as a CGI program.
The extension argument is case-insensitive, and can be specified with or without a leading dot.
See also: Files with multiple extensions, SetHandler
The AddLanguage directive maps the given filename extension to the specified content language. MIME-lang is the MIME language of filenames containing extension. This mapping is added to any already in force, overriding any mappings that already exist for the same extension.
Example:
AddEncoding x-compress .Z
AddLanguage en .en
AddLanguage fr .fr
Then the document xxxx.en.Z
will be treated as
being a compressed English document (as will the document
xxxx.Z.en
). Although the content language is
reported to the client, the browser is unlikely to use this
information. The AddLanguage directive is more useful for content negotiation,
where the server returns one from several documents based on
the client's language preference.
If multiple language assignments are made for the same extension, the last one encountered is the one that is used. That is, for the case of:
AddLanguage en .en AddLanguage en-uk .en AddLanguage en-us .en
documents with the extension ".en
" would be
treated as being "en-us
".
The extension argument is case-insensitive, and can be specified with or without a leading dot.
See also: Files with
multiple extensions, DefaultLanguage
See also: mod_negotiation
The AddType directive maps the given filename extensions
onto the specified content type. MIME-type is the MIME
type to use for filenames containing extension. This
mapping is added to any already in force, overriding any
mappings that already exist for the same extension.
This directive can be used to add mappings not listed in the
MIME types file (see the TypesConfig
directive).
Example:
AddType image/gif .gif
It is recommended that new MIME types be added using the
AddType directive rather than changing the TypesConfig file.
Note that, unlike the NCSA httpd, this directive cannot be used to set the type of particular files.
The extension argument is case-insensitive, and can be specified with or without a leading dot.
See also: Files with multiple extensions
The DefaultLanguage directive tells Apache that all files in
the directive's scope (e.g., all files covered by the
current <Directory>
container) that don't
have an explicit language extension (such as .fr
or .de as configured by AddLanguage)
should be considered to be in the specified MIME-lang
language. This allows entire directories to be marked as
containing Dutch content, for instance, without having to
rename each file. Note that unlike using extensions to specify
languages, DefaultLanguage can only specify a
single language.
For example:
DefaultLanguage fr
If no DefaultLanguage directive is in force, and a file does not have any language extensions as configured by AddLanguage, then that file will be considered to have no language attribute.
See also: mod_negotiation
See also: Files with
multiple extensions
When placed into an .htaccess
file or a
<Directory>
or <Location>
section, this directive forces all matching files to be served
as the content type given by media type. For example,
if you had a directory full of GIF files, but did not want to
label them all with ".gif", you might want to use:
ForceType image/gif
Note that this will override any filename extensions that might determine the media type.
You can override any none
:
# force all files to be image/gif: <Location /images> ForceType image/gif </Location> # but normal mime-type associations here: <Location /images/mixed> ForceType none </Location>
See also: AddType
The RemoveEncoding directive removes any
encoding associations for files with the given extensions. This
allows .htaccess
files in subdirectories to undo
any associations inherited from parent directories or the
server config files. An example of its use might be:
/foo/.htaccess:
AddEncoding x-gzip .gz
AddType text/plain .asc
<Files *.gz.asc>
RemoveEncoding
.gz
</Files>
This will cause foo.gz
to mark as being encoded
with the gzip method, but foo.gz.asc
as an
unencoded plaintext file.
Note:RemoveEncoding directives are processed after any AddEncoding directives, so it is possible they may undo the effects of the latter if both occur within the same directory configuration.
The extension argument is case-insensitive, and can be specified with or without a leading dot.
The RemoveHandler directive removes any handler
associations for files with the given extensions. This allows
.htaccess
files in subdirectories to undo any
associations inherited from parent directories or the server
config files. An example of its use might be:
/foo/.htaccess:
AddHandler server-parsed .html
/foo/bar/.htaccess:
RemoveHandler .html
This has the effect of returning .html files in the /foo/bar directory to being treated as normal files, rather than as candidates for parsing (see the mod_include module).
The extension argument is case-insensitive, and can be specified with or without a leading dot.
The RemoveType directive removes any MIME type
associations for files with the given extensions. This allows
.htaccess
files in subdirectories to undo any
associations inherited from parent directories or the server
config files. An example of its use might be:
/foo/.htaccess:
RemoveType .cgi
This will remove any special handling of .cgi
files in the /foo/
directory and any beneath it,
causing the files to be treated as being of the default type.
Note:RemoveType
directives are processed
after any AddType
directives, so it is
possible they may undo the effects of the latter if both occur
within the same directory configuration.
The extension argument is case-insensitive, and can be specified with or without a leading dot.
When placed into an .htaccess
file or a
<Directory>
or <Location>
section, this directive forces all matching files to be parsed
through the handler given by
handler-name. For example, if you had a directory you
wanted to be parsed entirely as imagemap rule files, regardless
of extension, you might put the following into an
.htaccess
file in that directory:
SetHandler imap-file
Another example: if you wanted to have the server display a
status report whenever a URL of
http://servername/status
was called, you might put
the following into access.conf: (See mod_status for more details.)
<Location /status> SetHandler server-status </Location>
You can override an earlier defined SetHandler
directive by using the value None
.
See also: AddHandler
TypesConfig
conf/mime.types
The TypesConfig directive sets the location of the MIME types configuration file. Filename is relative to the ServerRoot. This file sets the default list of mappings from filename extensions to content types; changing this file is not recommended. Use the AddType directive instead. The file contains lines in the format of the arguments to an AddType command:
MIME-type extension extension ...The extensions are lower-cased. Blank lines, and lines beginning with a hash character (`#') are ignored.