1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
4 <TITLE>Apache module mod_mime</TITLE>
7 <!-- Background white, links blue (unvisited), navy (visited), red (active) -->
15 <!--#include virtual="header.html" -->
16 <H1 ALIGN="CENTER">Module mod_mime</H1>
18 This module is contained in the <CODE>mod_mime.c</CODE> file, and is
19 compiled in by default. It provides for determining the types of files
24 This module is used to determine various bits of "meta information"
25 about documents. This information relates to the content of the
26 document and is returned to the browser or used in content-negotiation
27 within the server. In addition, a "handler" can be set for a document,
28 which determines how the document will be processed within the server.
32 The directives <A HREF="#addencoding">AddEncoding</A>, <A
33 HREF="#addhandler">AddHandler</A>, <A
34 HREF="#addlanguage">AddLanguage</A> and <A HREF="#addtype">AddType</A>
35 are all used to map file extensions onto the meta-information for that
36 file. Respectively they set the content-encoding, handler,
37 content-language and MIME-type (content-type) of documents. The
38 directive <A HREF="#typesconfig">TypesConfig</A> is used to specify a
39 file which also maps extensions onto MIME types. The directives <A
40 HREF="#forcetype">ForceType</A> and <A
41 HREF="#sethandler">SetHandler</A> are used to associated all the files
42 in a given location (<EM>e.g.</EM>, a particular directory) onto a particular
47 Note that changing the type or encoding of a file does not change the
48 value of the <CODE>Last-Modified</CODE> header. Thus, previously cached
49 copies may still be used by a client or proxy, with the previous headers.
51 <H2><A NAME="multipleext">Files with Multiple Extensions</A></H2>
53 Files can have more than one extension, and the order of the
54 extensions is <EM>normally</EM> irrelevant. For example, if the file
55 <CODE>welcome.html.fr</CODE> maps onto content type text/html and
56 language French then the file <CODE>welcome.fr.html</CODE> will map
57 onto exactly the same information. The only exception to this is if an
58 extension is given which Apache does not know how to handle. In this
59 case it will "forget" about any information it obtained from
60 extensions to the left of the unknown extension. So, for example, if
61 the extensions fr and html are mapped to the appropriate language and
62 type but extension xxx is not assigned to anything, then the file
63 <CODE>welcome.fr.xxx.html</CODE> will be associated with content-type
64 text/html but <EM>no</EM> language.
68 If more than one extension is given which maps onto the same type of
69 meta-information, then the one to the right will be used. For example,
70 if ".gif" maps to the MIME-type image/gif and ".html" maps to the
71 MIME-type text/html, then the file <CODE>welcome.gif.html</CODE> will
72 be associated with the MIME-type "text/html".
76 Care should be taken when a file with multiple extensions gets
77 associated with both a MIME-type and a handler. This will usually
78 result in the request being by the module associated with the
79 handler. For example, if the <CODE>.imap</CODE> extension is mapped to
80 the handler "imap-file" (from mod_imap) and the <CODE>.html</CODE>
81 extension is mapped to the MIME-type "text/html", then the file
82 <CODE>world.imap.html</CODE> will be associated with both the
83 "imap-file" handler and "text/html" MIME-type. When it is processed,
84 the "imap-file" handler will be used, and so it will be treated as a
85 mod_imap imagemap file.
89 <LI><A HREF="#addencoding">AddEncoding</A>
90 <LI><A HREF="#addhandler">AddHandler</A>
91 <LI><A HREF="#addlanguage">AddLanguage</A>
92 <LI><A HREF="#addtype">AddType</A>
93 <LI><A HREF="#defaultlanguage">DefaultLanguage</A>
94 <LI><A HREF="#forcetype">ForceType</A>
95 <LI><A HREF="#removehandler">RemoveHandler</A>
96 <LI><A HREF="#sethandler">SetHandler</A>
97 <LI><A HREF="#typesconfig">TypesConfig</A>
102 <H2><A NAME="addencoding">AddEncoding</A></H2>
103 <!--%plaintext <?INDEX {\tt AddEncoding} directive> -->
105 HREF="directive-dict.html#Syntax"
107 ><STRONG>Syntax:</STRONG></A> AddEncoding <EM>MIME-enc extension extension...</EM><BR>
109 HREF="directive-dict.html#Context"
111 ><STRONG>Context:</STRONG></A> server config, virtual host, directory, .htaccess<BR>
113 HREF="directive-dict.html#Override"
115 ><STRONG>Override:</STRONG></A> FileInfo<BR>
117 HREF="directive-dict.html#Status"
119 ><STRONG>Status:</STRONG></A> Base<BR>
121 HREF="directive-dict.html#Module"
123 ><STRONG>Module:</STRONG></A> mod_mime<P>
125 The AddEncoding directive maps the given filename extensions to the
126 specified encoding type. <EM>MIME-enc</EM> is the MIME encoding to use
127 for documents containing the <EM>extension</EM>. This mapping is added
128 to any already in force, overriding any mappings that already exist
129 for the same <EM>extension</EM>.
132 <BLOCKQUOTE><CODE> AddEncoding x-gzip gz<BR> AddEncoding x-compress Z
135 This will cause filenames containing the .gz extension to be marked as
136 encoded using the x-gzip encoding, and filenames containing the .Z
137 extension to be marked as encoded with x-compress.<P>
139 Old clients expect <CODE>x-gzip</CODE> and <CODE>x-compress</CODE>,
140 however the standard dictates that they're equivalent to <CODE>gzip</CODE>
141 and <CODE>compress</CODE> respectively. Apache does content encoding
142 comparisons by ignoring any leading <CODE>x-</CODE>. When responding
143 with an encoding Apache will use whatever form (<EM>i.e.</EM>, <CODE>x-foo</CODE>
144 or <CODE>foo</CODE>) the client requested. If the client didn't
145 specifically request a particular form Apache will use the form given by
146 the <CODE>AddEncoding</CODE> directive. To make this long story short,
147 you should always use <CODE>x-gzip</CODE> and <CODE>x-compress</CODE>
148 for these two specific encodings. More recent encodings, such as
149 <CODE>deflate</CODE> should be specified without the <CODE>x-</CODE>.
153 <STRONG>See also</STRONG>: <A HREF="#multipleext">Files with
154 multiple extensions</A>
158 <H2><A NAME="addhandler">AddHandler</A></H2>
161 HREF="directive-dict.html#Syntax"
163 ><STRONG>Syntax:</STRONG></A> AddHandler <EM>handler-name extension extension...</EM><BR>
165 HREF="directive-dict.html#Context"
167 ><STRONG>Context:</STRONG></A> server config, virtual host, directory, .htaccess<BR>
169 HREF="directive-dict.html#Override"
171 ><STRONG>Override:</STRONG></A> FileInfo<BR>
173 HREF="directive-dict.html#Status"
175 ><STRONG>Status:</STRONG></A> Base<BR>
177 HREF="directive-dict.html#Module"
179 ><STRONG>Module:</STRONG></A> mod_mime<BR>
181 HREF="directive-dict.html#Compatibility"
183 ><STRONG>Compatibility:</STRONG></A> AddHandler is only available in Apache
186 <P>AddHandler maps the filename extensions <EM>extension</EM> to the
187 <A HREF="../handler.html">handler</A> <EM>handler-name</EM>. This
188 mapping is added to any already in force, overriding any mappings that
189 already exist for the same <EM>extension</EM>.
191 For example, to activate CGI scripts
192 with the file extension "<CODE>.cgi</CODE>", you might use:
194 AddHandler cgi-script cgi
197 <P>Once that has been put into your srm.conf or httpd.conf file, any
198 file containing the "<CODE>.cgi</CODE>" extension will be treated as a
203 <STRONG>See also</STRONG>: <A HREF="#multipleext">Files with
204 multiple extensions</A>
208 <H2><A NAME="addlanguage">AddLanguage</A></H2>
209 <!--%plaintext <?INDEX {\tt AddLanguage} directive> -->
211 HREF="directive-dict.html#Syntax"
213 ><STRONG>Syntax:</STRONG></A> AddLanguage <EM>MIME-lang extension extension...</EM><BR>
215 HREF="directive-dict.html#Context"
217 ><STRONG>Context:</STRONG></A> server config, virtual host, directory, .htaccess<BR>
219 HREF="directive-dict.html#Override"
221 ><STRONG>Override:</STRONG></A> FileInfo<BR>
223 HREF="directive-dict.html#Status"
225 ><STRONG>Status:</STRONG></A> Base<BR>
227 HREF="directive-dict.html#Module"
229 ><STRONG>Module:</STRONG></A> mod_mime
232 The AddLanguage directive maps the given filename extensions to the
233 specified content language. <EM>MIME-lang</EM> is the MIME language of
234 filenames containing <EM>extension</EM>. This mapping is added to any
235 already in force, overriding any mappings that already exist for the
236 same <EM>extension</EM>.
239 Example: <BLOCKQUOTE><CODE>
240 AddEncoding x-compress Z<BR> AddLanguage en .en<BR> AddLanguage fr
241 .fr<BR> </CODE></BLOCKQUOTE>
244 Then the document <CODE>xxxx.en.Z</CODE> will be treated as being a
245 compressed English document (as will the document
246 <CODE>xxxx.Z.en</CODE>). Although the content language is reported to
247 the client, the browser is unlikely to use this information. The
248 AddLanguage directive is more useful for
249 <A HREF="../content-negotiation.html">content negotiation</A>, where
250 the server returns one from several documents based on the client's
254 If multiple language assignments are made for the same extension,
255 the last one encountered is the one that is used. That is, for the
260 AddLanguage en-uk .en
261 AddLanguage en-us .en
264 documents with the extension "<CODE>.en</CODE>" would be treated as
265 being "<CODE>en-us</CODE>".
268 <STRONG>See also</STRONG>: <A HREF="#multipleext">Files with
269 multiple extensions</A>
271 <STRONG>See also</STRONG>: <A
272 HREF="./mod_negotiation.html">mod_negotiation</A>
277 <H2><A NAME="addtype">AddType</A></H2>
278 <!--%plaintext <?INDEX {\tt AddType} directive> -->
280 HREF="directive-dict.html#Syntax"
282 ><STRONG>Syntax:</STRONG></A> AddType <EM>MIME-type extension extension...</EM><BR>
284 HREF="directive-dict.html#Context"
286 ><STRONG>Context:</STRONG></A> server config, virtual host, directory, .htaccess<BR>
288 HREF="directive-dict.html#Override"
290 ><STRONG>Override:</STRONG></A> FileInfo<BR>
292 HREF="directive-dict.html#Status"
294 ><STRONG>Status:</STRONG></A> Base<BR>
296 HREF="directive-dict.html#Module"
298 ><STRONG>Module:</STRONG></A> mod_mime<P>
300 The AddType directive maps the given filename extensions onto the
301 specified content type. <EM>MIME-enc</EM> is the MIME type to use for
302 filenames containing <EM>extension</EM>. This mapping is added to any
303 already in force, overriding any mappings that already exist for the
304 same <EM>extension</EM>. This directive can be used to add mappings
305 not listed in the MIME types file (see the <CODE><A
306 HREF="#typesconfig">TypesConfig</A></CODE> directive).
310 AddType image/gif GIF
312 It is recommended that new MIME types be added using the AddType directive
313 rather than changing the <A HREF="#typesconfig">TypesConfig</A> file.<P>
314 Note that, unlike the NCSA httpd, this directive cannot be used to set the
315 type of particular files.<P>
319 <STRONG>See also</STRONG>: <A HREF="#multipleext">Files with
320 multiple extensions</A>
324 <H2><A NAME="defaultlanguage">DefaultLanguage</A></H2>
325 <!--%plaintext <?INDEX {\tt DefaultLanguage} directive> -->
327 HREF="directive-dict.html#Syntax"
329 ><STRONG>Syntax:</STRONG></A> DefaultLanguage <EM>MIME-lang</EM><BR>
331 HREF="directive-dict.html#Context"
333 ><STRONG>Context:</STRONG></A> server config, virtual host, directory, .htaccess<BR>
335 HREF="directive-dict.html#Override"
337 ><STRONG>Override:</STRONG></A> FileInfo<BR>
339 HREF="directive-dict.html#Status"
341 ><STRONG>Status:</STRONG></A> Base<BR>
343 HREF="directive-dict.html#Module"
345 ><STRONG>Module:</STRONG></A> mod_mime<P>
347 The DefaultLanguage directive tells Apache that all files in the
348 directive's scope (<EM>e.g.</EM>, all files covered by the current
349 <CODE><Directory></CODE> container) that don't have an explicit
350 language extension (such as <SAMP>.fr</SAMP> or <SAMP>.de</SAMP> as
351 configured by <SAMP>AddLanguage</SAMP>) should be considered to be in
352 the specified <EM>MIME-lang</EM> language. This allows entire
353 directories to be marked as containing Dutch content, for instance,
354 without having to rename each file. Note that unlike using extensions
355 to specify languages, <SAMP>DefaultLanguage</SAMP> can only specify a
360 If no <SAMP>DefaultLanguage</SAMP> directive is in force, and a file
361 does not have any language extensions as configured by
362 <SAMP>AddLanguage</SAMP>, then that file will be considered to have no
367 <STRONG>See also</STRONG>: <A
368 HREF="./mod_negotiation.html">mod_negotiation</A>
370 <STRONG>See also</STRONG>: <A HREF="#multipleext">Files with
371 multiple extensions</A>
375 <H2><A NAME="forcetype">ForceType</A></H2>
378 HREF="directive-dict.html#Syntax"
380 ><STRONG>Syntax:</STRONG></A> ForceType <EM>media type</EM><BR>
382 HREF="directive-dict.html#Context"
384 ><STRONG>Context:</STRONG></A> directory, .htaccess<BR>
386 HREF="directive-dict.html#Status"
388 ><STRONG>Status:</STRONG></A> Base<BR>
390 HREF="directive-dict.html#Module"
392 ><STRONG>Module:</STRONG></A> mod_mime<BR>
394 HREF="directive-dict.html#Compatibility"
396 ><STRONG>Compatibility:</STRONG></A> ForceType is only available in Apache
399 <P>When placed into an <CODE>.htaccess</CODE> file or a
400 <CODE><Directory></CODE> or <CODE><Location></CODE> section,
401 this directive forces all matching files to be served
402 as the content type given by <EM>media type</EM>. For example, if you
403 had a directory full of GIF files, but did not want to label them all with
404 ".gif", you might want to use:
408 <P>Note that this will override any filename extensions that might determine
409 the media type.</P><HR>
411 <H2><A NAME="removehandler">RemoveHandler</A></H2>
414 HREF="directive-dict.html#Syntax"
416 ><STRONG>Syntax:</STRONG></A> RemoveHandler <EM>extension extension...</EM><BR>
418 HREF="directive-dict.html#Context"
420 ><STRONG>Context:</STRONG></A> directory, .htaccess<BR>
422 HREF="directive-dict.html#Status"
424 ><STRONG>Status:</STRONG></A> Base<BR>
426 HREF="directive-dict.html#Module"
428 ><STRONG>Module:</STRONG></A> mod_mime<BR>
430 HREF="directive-dict.html#Compatibility"
432 ><STRONG>Compatibility:</STRONG></A> RemoveHandler is only available in Apache
436 The <SAMP>RemoveHandler</SAMP> directive removes any
437 handler associations for files with the given extensions.
438 This allows <CODE>.htaccess</CODE> files in subdirectories to undo
439 any associations inherited from parent directories or the server
440 config files. An example of its use might be:
443 <DT><CODE>/foo/.htaccess:</CODE></DT>
444 <DD><CODE>AddHandler server-parsed .html</CODE></DD>
445 <DT><CODE>/foo/bar/.htaccess:</CODE></DT>
446 <DD><CODE>RemoveHandler .html</CODE></DD>
449 This has the effect of returning <SAMP>.html</SAMP> files in the
450 <SAMP>/foo/bar</SAMP> directory to being treated as normal
451 files, rather than as candidates for parsing (see the
452 <A HREF="mod_include.html"><SAMP>mod_include</SAMP></A> module).
456 <H2><A NAME="sethandler">SetHandler</A></H2>
459 HREF="directive-dict.html#Syntax"
461 ><STRONG>Syntax:</STRONG></A> SetHandler <EM>handler-name</EM><BR>
463 HREF="directive-dict.html#Context"
465 ><STRONG>Context:</STRONG></A> directory, .htaccess<BR>
467 HREF="directive-dict.html#Status"
469 ><STRONG>Status:</STRONG></A> Base<BR>
471 HREF="directive-dict.html#Module"
473 ><STRONG>Module:</STRONG></A> mod_mime<BR>
475 HREF="directive-dict.html#Compatibility"
477 ><STRONG>Compatibility:</STRONG></A> SetHandler is only available in Apache
480 <P>When placed into an <CODE>.htaccess</CODE> file or a
481 <CODE><Directory></CODE> or <CODE><Location></CODE> section,
482 this directive forces all matching files to be parsed through the
483 <A HREF="../handler.html">handler</A>
484 given by <EM>handler-name</EM>. For example, if you had a
485 directory you wanted to be parsed entirely as imagemap rule files,
486 regardless of extension, you might put the following into an
487 <CODE>.htaccess</CODE> file in that directory:
492 <P>Another example: if you wanted to have the server display a status
493 report whenever a URL of <CODE>http://servername/status</CODE> was
494 called, you might put the following into access.conf:
496 <Location /status>
497 SetHandler server-status
502 <H2><A NAME="typesconfig">TypesConfig</A></H2>
503 <!--%plaintext <?INDEX {\tt TypesConfig} directive> -->
505 HREF="directive-dict.html#Syntax"
507 ><STRONG>Syntax:</STRONG></A> TypesConfig <EM>filename</EM><BR>
509 HREF="directive-dict.html#Default"
511 ><STRONG>Default:</STRONG></A> <CODE>TypesConfig conf/MIME.types</CODE><BR>
513 HREF="directive-dict.html#Context"
515 ><STRONG>Context:</STRONG></A> server config<BR>
517 HREF="directive-dict.html#Status"
519 ><STRONG>Status:</STRONG></A> Base<BR>
521 HREF="directive-dict.html#Module"
523 ><STRONG>Module:</STRONG></A> mod_mime<P>
525 The TypesConfig directive sets the location of the MIME types configuration
526 file. <EM>Filename</EM> is relative to the
527 <A HREF="core.html#serverroot">ServerRoot</A>. This file sets the default list of
528 mappings from filename extensions to content types; changing this file is not
529 recommended. Use the <A HREF="#addtype">AddType</A> directive instead. The
530 file contains lines in the format of the arguments to an AddType command:
531 <BLOCKQUOTE><EM>MIME-type extension extension ...</EM></BLOCKQUOTE>
532 The extensions are lower-cased. Blank lines, and lines beginning with a hash
533 character (`#') are ignored.<P>
535 <!--#include virtual="footer.html" -->