mod_mime.html revision 1997e02bed99bd0c081962ade257a0ea12ebe15b
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<TITLE>Apache module mod_mime</TITLE>
</HEAD>
<!-- Background white, links blue (unvisited), navy (visited), red (active) -->
<BODY
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#000080"
ALINK="#FF0000"
>
<!--#include virtual="header.html" -->
<H1 ALIGN="CENTER">Module mod_mime</H1>
<p>This module provides for determining the types of files
from the filename and for association of handlers with files.</p>
<P><A
HREF="module-dict.html#Status"
REL="Help"
><STRONG>Status:</STRONG></A> Base
<BR>
<A
HREF="module-dict.html#SourceFile"
REL="Help"
<BR>
<A
HREF="module-dict.html#ModuleIdentifier"
REL="Help"
><STRONG>Module Identifier:</STRONG></A> mime_module
</P>
<H2>Summary</H2>
This module is used to determine various bits of "meta information"
about documents. This information relates to the content of the
document and is returned to the browser or used in content-negotiation
within the server. In addition, a "handler" can be set for a document,
which determines how the document will be processed within the server.
<P>
The directives <a href="#addcharset">AddCharset</a>,
<A HREF="#addencoding">AddEncoding</A>, <A HREF="#addhandler">AddHandler</A>,
<A HREF="#SetFilter">SetFilter</A>, <A HREF="#addlanguage">AddLanguage</A>
and <A HREF="#addtype">AddType</A> 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 <A HREF="#typesconfig">TypesConfig</A> is used to
specify a file which also maps extensions onto MIME types. The directives
<A HREF="#forcetype">ForceType</A> and <A HREF="#sethandler">SetHandler</A>
particular directory) onto a particular MIME type or handler.
<P>
Note that changing the type or encoding of a file does not change the
value of the <CODE>Last-Modified</CODE> header. Thus, previously cached
copies may still be used by a client or proxy, with the previous headers.
<H2>Directives</H2>
<UL>
<li><a href="#addcharset">AddCharset</a></li>
<LI><A HREF="#addencoding">AddEncoding</A>
<LI><A HREF="#addhandler">AddHandler</A>
<LI><A HREF="#setfilter">SetFilter</A>
<LI><A HREF="#addlanguage">AddLanguage</A>
<LI><A HREF="#addtype">AddType</A>
<LI><A HREF="#defaultlanguage">DefaultLanguage</A>
<LI><A HREF="#forcetype">ForceType</A>
<LI><A HREF="#removehandler">RemoveHandler</A>
<LI><A HREF="#sethandler">SetHandler</A>
<LI><A HREF="#typesconfig">TypesConfig</A>
</UL>
<p>See also: <a
<H2><A NAME="multipleext">Files with Multiple Extensions</A></H2>
Files can have more than one extension, and the order of the
extensions is <EM>normally</EM> irrelevant. For example, if the file
onto exactly the same information. The only exception to this is if an
extension is given which Apache does not know how to handle. In this
case it will "forget" about any information it obtained from
extensions to the left of the unknown extension. So, for example, if
the extensions fr and html are mapped to the appropriate language and
type but extension xxx is not assigned to anything, then the file
<P>
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. For example,
<P>
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 <CODE>.imap</CODE> extension is mapped to
the handler "imap-file" (from mod_imap) and the <CODE>.html</CODE>
the "imap-file" handler will be used, and so it will be treated as a
mod_imap imagemap file.
<HR>
<H2><A NAME="addcharset">AddCharset</A> directive</H2>
><STRONG>Syntax:</STRONG></A> AddCharset <em>charset extension</em>
[<em>extension</em>] ...<br>
><STRONG>Context:</STRONG></A> server config, virtual host, directory, .htaccess<BR>
<A
HREF="directive-dict.html#Override"
REL="Help"
><STRONG>Override:</STRONG></A> FileInfo<BR>
<A
HREF="directive-dict.html#Status"
REL="Help"
><STRONG>Status:</STRONG></A> Base<BR>
<A
HREF="directive-dict.html#Module"
REL="Help"
><STRONG>Module:</STRONG></A> mod_mime
<P>
The AddCharset directive maps the given filename extensions to the
specified content charset. <i>charset</i> is the MIME charset
parameter of filenames containing <i>extension</i>. This mapping is
added to any already in force, overriding any mappings that already
exist for the same <i>extension</i>.
</P>
<P>
Example:
<pre>
AddLanguage ja .ja
AddCharset EUC-JP .euc
AddCharset ISO-2022-JP .jis
AddCharset SHIFT_JIS .sjis
</pre>
<P>
Japanese document whose charset is ISO-2022-JP (as will the document
to inform the client about the character encoding of the document so
that the document can be interpreted and displayed appropriately, and
the server returns one from several documents based on the client's
charset preference.
</P>
<p>The <em>extension</em> argument is case-insensitive, and can
be specified with or without a leading dot.</p>
<P>
</P>
<hr>
<H2><A NAME="addencoding">AddEncoding</A> directive</H2>
<!--%plaintext <?INDEX {\tt AddEncoding} directive> -->
<A
HREF="directive-dict.html#Syntax"
REL="Help"
><STRONG>Syntax:</STRONG></A> AddEncoding <EM>MIME-enc extension</em>
[<em>extension</EM>] ...<BR>
<A
HREF="directive-dict.html#Context"
REL="Help"
><STRONG>Context:</STRONG></A> server config, virtual host, directory, .htaccess<BR>
<A
HREF="directive-dict.html#Override"
REL="Help"
><STRONG>Override:</STRONG></A> FileInfo<BR>
<A
HREF="directive-dict.html#Status"
REL="Help"
><STRONG>Status:</STRONG></A> Base<BR>
<A
HREF="directive-dict.html#Module"
REL="Help"
><STRONG>Module:</STRONG></A> mod_mime<P>
The AddEncoding directive maps the given filename extensions to the
specified encoding type. <EM>MIME-enc</EM> is the MIME encoding to use
for documents containing the <EM>extension</EM>. This mapping is added
to any already in force, overriding any mappings that already exist
for the same <EM>extension</EM>.
Example:
<BLOCKQUOTE><CODE>
AddEncoding x-gzip .gz<BR>
AddEncoding x-compress .Z
</CODE></BLOCKQUOTE>
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.<P>
Old clients expect <CODE>x-gzip</CODE> and <CODE>x-compress</CODE>,
however the standard dictates that they're equivalent to <CODE>gzip</CODE>
and <CODE>compress</CODE> respectively. Apache does content encoding
comparisons by ignoring any leading <CODE>x-</CODE>. When responding
or <CODE>foo</CODE>) the client requested. If the client didn't
specifically request a particular form Apache will use the form given by
the <CODE>AddEncoding</CODE> directive. To make this long story short,
you should always use <CODE>x-gzip</CODE> and <CODE>x-compress</CODE>
for these two specific encodings. More recent encodings, such as
<CODE>deflate</CODE> should be specified without the <CODE>x-</CODE>.
<p>The <em>extension</em> argument is case-insensitive, and can
be specified with or without a leading dot.</p>
<P>
<STRONG>See also</STRONG>: <A HREF="#multipleext">Files with
multiple extensions</A>
<P><HR>
<H2><A NAME="addhandler">AddHandler</A> directive</H2>
<A
HREF="directive-dict.html#Syntax"
REL="Help"
><STRONG>Syntax:</STRONG></A> AddHandler <EM>handler-name extension</em>
[<em>extension</EM>] ...<BR>
<A
HREF="directive-dict.html#Context"
REL="Help"
><STRONG>Context:</STRONG></A> server config, virtual host, directory, .htaccess<BR>
<A
HREF="directive-dict.html#Override"
REL="Help"
><STRONG>Override:</STRONG></A> FileInfo<BR>
<A
HREF="directive-dict.html#Status"
REL="Help"
><STRONG>Status:</STRONG></A> Base<BR>
<A
HREF="directive-dict.html#Module"
REL="Help"
><STRONG>Module:</STRONG></A> mod_mime
<P>AddHandler maps the filename extensions <EM>extension</EM> to the
mapping is added to any already in force, overriding any mappings that
already exist for the same <EM>extension</EM>.
For example, to activate CGI scripts
with the file extension "<CODE>.cgi</CODE>", you might use:
<PRE>
AddHandler cgi-script .cgi
</PRE>
file containing the "<CODE>.cgi</CODE>" extension will be treated as a
CGI program.</P>
<p>The <em>extension</em> argument is case-insensitive, and can
be specified with or without a leading dot.</p>
<P>
<STRONG>See also</STRONG>: <A HREF="#multipleext">Files with
multiple extensions</A>
<HR>
<H2><A NAME="addlanguage">AddLanguage</A> directive</H2>
<!--%plaintext <?INDEX {\tt AddLanguage} directive> -->
<A
HREF="directive-dict.html#Syntax"
REL="Help"
><STRONG>Syntax:</STRONG></A> AddLanguage <EM>MIME-lang extension</em>
[<em>extension</EM>] ...<BR>
<A
HREF="directive-dict.html#Context"
REL="Help"
><STRONG>Context:</STRONG></A> server config, virtual host, directory, .htaccess<BR>
<A
HREF="directive-dict.html#Override"
REL="Help"
><STRONG>Override:</STRONG></A> FileInfo<BR>
<A
HREF="directive-dict.html#Status"
REL="Help"
><STRONG>Status:</STRONG></A> Base<BR>
<A
HREF="directive-dict.html#Module"
REL="Help"
><STRONG>Module:</STRONG></A> mod_mime
<P>
The AddLanguage directive maps the given filename extensions to the
specified content language. <EM>MIME-lang</EM> is the MIME language of
filenames containing <EM>extension</EM>. This mapping is added to any
already in force, overriding any mappings that already exist for the
same <EM>extension</EM>.
</P>
<P>
Example: <BLOCKQUOTE><CODE>
AddEncoding x-compress .Z<BR> AddLanguage en .en<BR> AddLanguage fr
.fr<BR> </CODE></BLOCKQUOTE>
</P>
<P>
compressed English document (as will the document
the client, the browser is unlikely to use this information. The
AddLanguage directive is more useful for
the server returns one from several documents based on the client's
language preference.
</P>
<P>
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:
</P>
<PRE>
AddLanguage en .en
AddLanguage en-uk .en
AddLanguage en-us .en
</PRE>
<P>
documents with the extension "<CODE>.en</CODE>" would be treated as
being "<CODE>en-us</CODE>".
</P>
<p>The <em>extension</em> argument is case-insensitive, and can
be specified with or without a leading dot.</p>
<P>
<STRONG>See also</STRONG>: <A HREF="#multipleext">Files with
multiple extensions</A>
<BR>
<STRONG>See also</STRONG>: <A
HREF="/mod_negotiation.html">mod_negotiation</A>
</P>
<HR>
<H2><A NAME="setfilter">SetFilter</A> directive</H2>
<!--%plaintext <?INDEX {\tt SetFilter} directive> -->
<A
HREF="directive-dict.html#Syntax"
REL="Help"
><STRONG>Syntax:</STRONG></A> SetFilter <em>MIME-type filter</em>
[<em>filter</em>] ...<br>
<A
HREF="directive-dict.html#Context"
REL="Help"
><STRONG>Context:</STRONG></A> server config, virtual host, directory, .htaccess<BR>
<A
HREF="directive-dict.html#Override"
REL="Help"
><STRONG>Override:</STRONG></A> FileInfo<BR>
<A
HREF="directive-dict.html#Status"
REL="Help"
><STRONG>Status:</STRONG></A> Base<BR>
<A
HREF="directive-dict.html#Module"
REL="Help"
><STRONG>Module:</STRONG></A> mod_mime
<P>
The SetFilter directive maps a filter stack to the specified MIME-type.
</P>
<P>
Example: <BLOCKQUOTE><CODE>
SetFilter server-parsed INCLUDES CACHE
</CODE></BLOCKQUOTE>
</P>
<P>
Then any document with the server-parsed MIME-type will pass through the
INCLUDES and CACHE filters. The filters are added in the same order that
they are specified in the config file.
</P>
<P>
This can be very powerful when combined with the <A HREF="#addtype">
AddType</A> directive. This allows you to specify an extension for a
MIME-type and a set of filters for files with those extensions to be passed
through
</P>
<PRE>
</PRE>
<P>
documents with the extension "<CODE>.shtml</CODE>" would be passed through
the INCLUDES filter.
</P>
<P>
<HR>
<H2><A NAME="addtype">AddType</A> directive</H2>
<!--%plaintext <?INDEX {\tt AddType} directive> -->
<A
HREF="directive-dict.html#Syntax"
REL="Help"
><STRONG>Syntax:</STRONG></A> AddType <EM>MIME-type extension</em>
[<em>extension</EM>] ...<BR>
<A
HREF="directive-dict.html#Context"
REL="Help"
><STRONG>Context:</STRONG></A> server config, virtual host, directory, .htaccess<BR>
<A
HREF="directive-dict.html#Override"
REL="Help"
><STRONG>Override:</STRONG></A> FileInfo<BR>
<A
HREF="directive-dict.html#Status"
REL="Help"
><STRONG>Status:</STRONG></A> Base<BR>
<A
HREF="directive-dict.html#Module"
REL="Help"
><STRONG>Module:</STRONG></A> mod_mime<P>
The AddType directive maps the given filename extensions onto the
specified content type. <EM>MIME-enc</EM> is the MIME type to use for
filenames containing <EM>extension</EM>. This mapping is added to any
already in force, overriding any mappings that already exist for the
same <EM>extension</EM>. This directive can be used to add mappings
not listed in the MIME types file (see the <CODE><A
HREF="#typesconfig">TypesConfig</A></CODE> directive).
Example:
<BLOCKQUOTE><CODE>
</CODE></BLOCKQUOTE>
It is recommended that new MIME types be added using the AddType directive
rather than changing the <A HREF="#typesconfig">TypesConfig</A> file.<P>
Note that, unlike the NCSA httpd, this directive cannot be used to set the
type of particular files.<P>
<p>The <em>extension</em> argument is case-insensitive, and can
be specified with or without a leading dot.</p>
<P>
<STRONG>See also</STRONG>: <A HREF="#multipleext">Files with
multiple extensions</A>
<HR>
<H2><A NAME="defaultlanguage">DefaultLanguage</A> directive</H2>
<!--%plaintext <?INDEX {\tt DefaultLanguage} directive> -->
<A
HREF="directive-dict.html#Syntax"
REL="Help"
><STRONG>Syntax:</STRONG></A> DefaultLanguage <EM>MIME-lang</EM><BR>
<A
HREF="directive-dict.html#Context"
REL="Help"
><STRONG>Context:</STRONG></A> server config, virtual host, directory, .htaccess<BR>
<A
HREF="directive-dict.html#Override"
REL="Help"
><STRONG>Override:</STRONG></A> FileInfo<BR>
<A
HREF="directive-dict.html#Status"
REL="Help"
><STRONG>Status:</STRONG></A> Base<BR>
<A
HREF="directive-dict.html#Module"
REL="Help"
><STRONG>Module:</STRONG></A> mod_mime
The DefaultLanguage directive tells Apache that all files in the
<CODE><Directory></CODE> container) that don't have an explicit
language extension (such as <SAMP>.fr</SAMP> or <SAMP>.de</SAMP> as
configured by <SAMP>AddLanguage</SAMP>) should be considered to be in
the specified <EM>MIME-lang</EM> 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, <SAMP>DefaultLanguage</SAMP> can only specify a
single language.
<P>
If no <SAMP>DefaultLanguage</SAMP> directive is in force, and a file
does not have any language extensions as configured by
<SAMP>AddLanguage</SAMP>, then that file will be considered to have no
language attribute.
<P>
<STRONG>See also</STRONG>: <A
HREF="/mod_negotiation.html">mod_negotiation</A>
<BR>
<STRONG>See also</STRONG>: <A HREF="#multipleext">Files with
multiple extensions</A>
<HR>
<H2><A NAME="forcetype">ForceType</A> directive</H2>
<A
HREF="directive-dict.html#Syntax"
REL="Help"
><STRONG>Syntax:</STRONG></A> ForceType <EM>media-type</EM><BR>
<A
HREF="directive-dict.html#Context"
REL="Help"
><STRONG>Context:</STRONG></A> directory, .htaccess<BR>
<A
HREF="directive-dict.html#Status"
REL="Help"
><STRONG>Status:</STRONG></A> Base<BR>
<A
HREF="directive-dict.html#Module"
REL="Help"
><STRONG>Module:</STRONG></A> mod_mime
<P>When placed into an <CODE>.htaccess</CODE> file or a
<CODE><Directory></CODE> or <CODE><Location></CODE> section,
this directive forces all matching files to be served
as the content type given by <EM>media type</EM>. 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:
<PRE>
</PRE>
<P>Note that this will override any filename extensions that might determine
the media type.</P><HR>
<H2><A NAME="removehandler">RemoveHandler</A> directive</H2>
<A
HREF="directive-dict.html#Syntax"
REL="Help"
><STRONG>Syntax:</STRONG></A> RemoveHandler <EM>extension</em>
[<em>extension</em>] ...<BR>
<A
HREF="directive-dict.html#Context"
REL="Help"
><STRONG>Context:</STRONG></A> directory, .htaccess<BR>
<A
HREF="directive-dict.html#Status"
REL="Help"
><STRONG>Status:</STRONG></A> Base<BR>
<A
HREF="directive-dict.html#Module"
REL="Help"
><STRONG>Module:</STRONG></A> mod_mime
<P>
The <SAMP>RemoveHandler</SAMP> directive removes any
handler associations for files with the given extensions.
This allows <CODE>.htaccess</CODE> files in subdirectories to undo
any associations inherited from parent directories or the server
config files. An example of its use might be:
</P>
<DL>
<DD><CODE>AddHandler server-parsed .html</CODE></DD>
<DD><CODE>RemoveHandler .html</CODE></DD>
</DL>
<P>
This has the effect of returning <SAMP>.html</SAMP> files in the
files, rather than as candidates for parsing (see the
</P>
<p>The <em>extension</em> argument is case-insensitive, and can
be specified with or without a leading dot.</p>
<HR>
<H2><A NAME="sethandler">SetHandler</A> directive</H2>
<A
HREF="directive-dict.html#Syntax"
REL="Help"
><STRONG>Syntax:</STRONG></A> SetHandler <EM>handler-name</EM><BR>
<A
HREF="directive-dict.html#Context"
REL="Help"
><STRONG>Context:</STRONG></A> directory, .htaccess<BR>
<A
HREF="directive-dict.html#Status"
REL="Help"
><STRONG>Status:</STRONG></A> Base<BR>
<A
HREF="directive-dict.html#Module"
REL="Help"
><STRONG>Module:</STRONG></A> mod_mime
<P>When placed into an <CODE>.htaccess</CODE> file or a
<CODE><Directory></CODE> or <CODE><Location></CODE> section,
this directive forces all matching files to be parsed through the
given by <EM>handler-name</EM>. 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
<CODE>.htaccess</CODE> file in that directory:
<PRE>
SetHandler imap-file
</PRE>
<P>Another example: if you wanted to have the server display a status
called, you might put the following into access.conf:
<PRE>
<Location /status>
SetHandler server-status
</Location>
</PRE>
<HR>
<H2><A NAME="typesconfig">TypesConfig</A> directive</H2>
<!--%plaintext <?INDEX {\tt TypesConfig} directive> -->
<A
HREF="directive-dict.html#Syntax"
REL="Help"
><STRONG>Syntax:</STRONG></A> TypesConfig <EM>filename</EM><BR>
<A
HREF="directive-dict.html#Default"
REL="Help"
<A
HREF="directive-dict.html#Context"
REL="Help"
><STRONG>Context:</STRONG></A> server config<BR>
<A
HREF="directive-dict.html#Status"
REL="Help"
><STRONG>Status:</STRONG></A> Base<BR>
<A
HREF="directive-dict.html#Module"
REL="Help"
><STRONG>Module:</STRONG></A> mod_mime<P>
The TypesConfig directive sets the location of the MIME types configuration
file. <EM>Filename</EM> is relative to the
mappings from filename extensions to content types; changing this file is not
recommended. Use the <A HREF="#addtype">AddType</A> directive instead. The
file contains lines in the format of the arguments to an AddType command:
<BLOCKQUOTE><EM>MIME-type extension extension ...</EM></BLOCKQUOTE>
The extensions are lower-cased. Blank lines, and lines beginning with a hash
character (`#') are ignored.<P>
<!--#include virtual="footer.html" -->
</BODY>
</HTML>