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="#addcharset">AddCharset</a>,
33 <A HREF="#addencoding">AddEncoding</A>, <A HREF="#addhandler">AddHandler</A>,
34 <A 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 character set, 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="#addcharset">AddCharset</a></li>
90 <LI><A HREF="#addencoding">AddEncoding</A>
91 <LI><A HREF="#addhandler">AddHandler</A>
92 <LI><A HREF="#addlanguage">AddLanguage</A>
93 <LI><A HREF="#addtype">AddType</A>
94 <LI><A HREF="#defaultlanguage">DefaultLanguage</A>
95 <LI><A HREF="#forcetype">ForceType</A>
96 <LI><A HREF="#removehandler">RemoveHandler</A>
97 <LI><A HREF="#sethandler">SetHandler</A>
98 <LI><A HREF="#typesconfig">TypesConfig</A>
102 <H2><A NAME="addcharset">AddCharset</A></H2>
103 <A HREF="directive-dict.html#Syntax" REL="Help"
104 ><STRONG>Syntax:</STRONG></A> AddCharset <i>charset extension
105 [extension...]</i><br>
106 <A HREF="directive-dict.html#Context" REL="Help"
107 ><STRONG>Context:</STRONG></A> server config, virtual host, directory, .htaccess<BR>
109 HREF="directive-dict.html#Override"
111 ><STRONG>Override:</STRONG></A> FileInfo<BR>
113 HREF="directive-dict.html#Status"
115 ><STRONG>Status:</STRONG></A> Base<BR>
117 HREF="directive-dict.html#Module"
119 ><STRONG>Module:</STRONG></A> mod_mime
121 <A HREF="directive-dict.html#Compatibility" REL="Help"
122 ><STRONG>Compatibility:</STRONG></A> AddCharset is only available in Apache
126 The AddCharset directive maps the given filename extensions to the
127 specified content charset. <i>charset</i> is the MIME charset
128 parameter of filenames containing <i>extension</i>. This mapping is
129 added to any already in force, overriding any mappings that already
130 exist for the same <i>extension</i>.
136 AddCharset EUC-JP .euc
137 AddCharset ISO-2022-JP .jis
138 AddCharset SHIFT_JIS .sjis
142 Then the document <samp>xxxx.ja.jis</samp> will be treated as being a
143 Japanese document whose charset is ISO-2022-JP (as will the document
144 <samp>xxxx.jis.ja</samp>). Although the content charset is reported to
145 the client, the browser is unlikely to use this information. The
146 AddCharset directive is more useful for
147 <A HREF="../content-negotiation.html">content negotiation</A>, where
148 the server returns one from several documents based on the client's
152 <STRONG>See also</STRONG>: <A HREF="mod_negotiation.html">mod_negotiation</A>
157 <H2><A NAME="addencoding">AddEncoding</A></H2>
158 <!--%plaintext <?INDEX {\tt AddEncoding} directive> -->
160 HREF="directive-dict.html#Syntax"
162 ><STRONG>Syntax:</STRONG></A> AddEncoding <EM>MIME-enc extension extension...</EM><BR>
164 HREF="directive-dict.html#Context"
166 ><STRONG>Context:</STRONG></A> server config, virtual host, directory, .htaccess<BR>
168 HREF="directive-dict.html#Override"
170 ><STRONG>Override:</STRONG></A> FileInfo<BR>
172 HREF="directive-dict.html#Status"
174 ><STRONG>Status:</STRONG></A> Base<BR>
176 HREF="directive-dict.html#Module"
178 ><STRONG>Module:</STRONG></A> mod_mime<P>
180 The AddEncoding directive maps the given filename extensions to the
181 specified encoding type. <EM>MIME-enc</EM> is the MIME encoding to use
182 for documents containing the <EM>extension</EM>. This mapping is added
183 to any already in force, overriding any mappings that already exist
184 for the same <EM>extension</EM>.
187 <BLOCKQUOTE><CODE> AddEncoding x-gzip gz<BR> AddEncoding x-compress Z
190 This will cause filenames containing the .gz extension to be marked as
191 encoded using the x-gzip encoding, and filenames containing the .Z
192 extension to be marked as encoded with x-compress.<P>
194 Old clients expect <CODE>x-gzip</CODE> and <CODE>x-compress</CODE>,
195 however the standard dictates that they're equivalent to <CODE>gzip</CODE>
196 and <CODE>compress</CODE> respectively. Apache does content encoding
197 comparisons by ignoring any leading <CODE>x-</CODE>. When responding
198 with an encoding Apache will use whatever form (<EM>i.e.</EM>, <CODE>x-foo</CODE>
199 or <CODE>foo</CODE>) the client requested. If the client didn't
200 specifically request a particular form Apache will use the form given by
201 the <CODE>AddEncoding</CODE> directive. To make this long story short,
202 you should always use <CODE>x-gzip</CODE> and <CODE>x-compress</CODE>
203 for these two specific encodings. More recent encodings, such as
204 <CODE>deflate</CODE> should be specified without the <CODE>x-</CODE>.
208 <STRONG>See also</STRONG>: <A HREF="#multipleext">Files with
209 multiple extensions</A>
213 <H2><A NAME="addhandler">AddHandler</A></H2>
216 HREF="directive-dict.html#Syntax"
218 ><STRONG>Syntax:</STRONG></A> AddHandler <EM>handler-name extension extension...</EM><BR>
220 HREF="directive-dict.html#Context"
222 ><STRONG>Context:</STRONG></A> server config, virtual host, directory, .htaccess<BR>
224 HREF="directive-dict.html#Override"
226 ><STRONG>Override:</STRONG></A> FileInfo<BR>
228 HREF="directive-dict.html#Status"
230 ><STRONG>Status:</STRONG></A> Base<BR>
232 HREF="directive-dict.html#Module"
234 ><STRONG>Module:</STRONG></A> mod_mime<BR>
236 HREF="directive-dict.html#Compatibility"
238 ><STRONG>Compatibility:</STRONG></A> AddHandler is only available in Apache
241 <P>AddHandler maps the filename extensions <EM>extension</EM> to the
242 <A HREF="../handler.html">handler</A> <EM>handler-name</EM>. This
243 mapping is added to any already in force, overriding any mappings that
244 already exist for the same <EM>extension</EM>.
246 For example, to activate CGI scripts
247 with the file extension "<CODE>.cgi</CODE>", you might use:
249 AddHandler cgi-script cgi
252 <P>Once that has been put into your srm.conf or httpd.conf file, any
253 file containing the "<CODE>.cgi</CODE>" extension will be treated as a
258 <STRONG>See also</STRONG>: <A HREF="#multipleext">Files with
259 multiple extensions</A>
263 <H2><A NAME="addlanguage">AddLanguage</A></H2>
264 <!--%plaintext <?INDEX {\tt AddLanguage} directive> -->
266 HREF="directive-dict.html#Syntax"
268 ><STRONG>Syntax:</STRONG></A> AddLanguage <EM>MIME-lang extension extension...</EM><BR>
270 HREF="directive-dict.html#Context"
272 ><STRONG>Context:</STRONG></A> server config, virtual host, directory, .htaccess<BR>
274 HREF="directive-dict.html#Override"
276 ><STRONG>Override:</STRONG></A> FileInfo<BR>
278 HREF="directive-dict.html#Status"
280 ><STRONG>Status:</STRONG></A> Base<BR>
282 HREF="directive-dict.html#Module"
284 ><STRONG>Module:</STRONG></A> mod_mime
287 The AddLanguage directive maps the given filename extensions to the
288 specified content language. <EM>MIME-lang</EM> is the MIME language of
289 filenames containing <EM>extension</EM>. This mapping is added to any
290 already in force, overriding any mappings that already exist for the
291 same <EM>extension</EM>.
294 Example: <BLOCKQUOTE><CODE>
295 AddEncoding x-compress Z<BR> AddLanguage en .en<BR> AddLanguage fr
296 .fr<BR> </CODE></BLOCKQUOTE>
299 Then the document <CODE>xxxx.en.Z</CODE> will be treated as being a
300 compressed English document (as will the document
301 <CODE>xxxx.Z.en</CODE>). Although the content language is reported to
302 the client, the browser is unlikely to use this information. The
303 AddLanguage directive is more useful for
304 <A HREF="../content-negotiation.html">content negotiation</A>, where
305 the server returns one from several documents based on the client's
309 If multiple language assignments are made for the same extension,
310 the last one encountered is the one that is used. That is, for the
315 AddLanguage en-uk .en
316 AddLanguage en-us .en
319 documents with the extension "<CODE>.en</CODE>" would be treated as
320 being "<CODE>en-us</CODE>".
323 <STRONG>See also</STRONG>: <A HREF="#multipleext">Files with
324 multiple extensions</A>
326 <STRONG>See also</STRONG>: <A
327 HREF="./mod_negotiation.html">mod_negotiation</A>
332 <H2><A NAME="addtype">AddType</A></H2>
333 <!--%plaintext <?INDEX {\tt AddType} directive> -->
335 HREF="directive-dict.html#Syntax"
337 ><STRONG>Syntax:</STRONG></A> AddType <EM>MIME-type extension extension...</EM><BR>
339 HREF="directive-dict.html#Context"
341 ><STRONG>Context:</STRONG></A> server config, virtual host, directory, .htaccess<BR>
343 HREF="directive-dict.html#Override"
345 ><STRONG>Override:</STRONG></A> FileInfo<BR>
347 HREF="directive-dict.html#Status"
349 ><STRONG>Status:</STRONG></A> Base<BR>
351 HREF="directive-dict.html#Module"
353 ><STRONG>Module:</STRONG></A> mod_mime<P>
355 The AddType directive maps the given filename extensions onto the
356 specified content type. <EM>MIME-enc</EM> is the MIME type to use for
357 filenames containing <EM>extension</EM>. This mapping is added to any
358 already in force, overriding any mappings that already exist for the
359 same <EM>extension</EM>. This directive can be used to add mappings
360 not listed in the MIME types file (see the <CODE><A
361 HREF="#typesconfig">TypesConfig</A></CODE> directive).
365 AddType image/gif GIF
367 It is recommended that new MIME types be added using the AddType directive
368 rather than changing the <A HREF="#typesconfig">TypesConfig</A> file.<P>
369 Note that, unlike the NCSA httpd, this directive cannot be used to set the
370 type of particular files.<P>
374 <STRONG>See also</STRONG>: <A HREF="#multipleext">Files with
375 multiple extensions</A>
379 <H2><A NAME="defaultlanguage">DefaultLanguage</A></H2>
380 <!--%plaintext <?INDEX {\tt DefaultLanguage} directive> -->
382 HREF="directive-dict.html#Syntax"
384 ><STRONG>Syntax:</STRONG></A> DefaultLanguage <EM>MIME-lang</EM><BR>
386 HREF="directive-dict.html#Context"
388 ><STRONG>Context:</STRONG></A> server config, virtual host, directory, .htaccess<BR>
390 HREF="directive-dict.html#Override"
392 ><STRONG>Override:</STRONG></A> FileInfo<BR>
394 HREF="directive-dict.html#Status"
396 ><STRONG>Status:</STRONG></A> Base<BR>
398 HREF="directive-dict.html#Module"
400 ><STRONG>Module:</STRONG></A> mod_mime<P>
402 The DefaultLanguage directive tells Apache that all files in the
403 directive's scope (<EM>e.g.</EM>, all files covered by the current
404 <CODE><Directory></CODE> container) that don't have an explicit
405 language extension (such as <SAMP>.fr</SAMP> or <SAMP>.de</SAMP> as
406 configured by <SAMP>AddLanguage</SAMP>) should be considered to be in
407 the specified <EM>MIME-lang</EM> language. This allows entire
408 directories to be marked as containing Dutch content, for instance,
409 without having to rename each file. Note that unlike using extensions
410 to specify languages, <SAMP>DefaultLanguage</SAMP> can only specify a
415 If no <SAMP>DefaultLanguage</SAMP> directive is in force, and a file
416 does not have any language extensions as configured by
417 <SAMP>AddLanguage</SAMP>, then that file will be considered to have no
422 <STRONG>See also</STRONG>: <A
423 HREF="./mod_negotiation.html">mod_negotiation</A>
425 <STRONG>See also</STRONG>: <A HREF="#multipleext">Files with
426 multiple extensions</A>
430 <H2><A NAME="forcetype">ForceType</A></H2>
433 HREF="directive-dict.html#Syntax"
435 ><STRONG>Syntax:</STRONG></A> ForceType <EM>media type</EM><BR>
437 HREF="directive-dict.html#Context"
439 ><STRONG>Context:</STRONG></A> directory, .htaccess<BR>
441 HREF="directive-dict.html#Status"
443 ><STRONG>Status:</STRONG></A> Base<BR>
445 HREF="directive-dict.html#Module"
447 ><STRONG>Module:</STRONG></A> mod_mime<BR>
449 HREF="directive-dict.html#Compatibility"
451 ><STRONG>Compatibility:</STRONG></A> ForceType is only available in Apache
454 <P>When placed into an <CODE>.htaccess</CODE> file or a
455 <CODE><Directory></CODE> or <CODE><Location></CODE> section,
456 this directive forces all matching files to be served
457 as the content type given by <EM>media type</EM>. For example, if you
458 had a directory full of GIF files, but did not want to label them all with
459 ".gif", you might want to use:
463 <P>Note that this will override any filename extensions that might determine
464 the media type.</P><HR>
466 <H2><A NAME="removehandler">RemoveHandler</A></H2>
469 HREF="directive-dict.html#Syntax"
471 ><STRONG>Syntax:</STRONG></A> RemoveHandler <EM>extension extension...</EM><BR>
473 HREF="directive-dict.html#Context"
475 ><STRONG>Context:</STRONG></A> directory, .htaccess<BR>
477 HREF="directive-dict.html#Status"
479 ><STRONG>Status:</STRONG></A> Base<BR>
481 HREF="directive-dict.html#Module"
483 ><STRONG>Module:</STRONG></A> mod_mime<BR>
485 HREF="directive-dict.html#Compatibility"
487 ><STRONG>Compatibility:</STRONG></A> RemoveHandler is only available in Apache
491 The <SAMP>RemoveHandler</SAMP> directive removes any
492 handler associations for files with the given extensions.
493 This allows <CODE>.htaccess</CODE> files in subdirectories to undo
494 any associations inherited from parent directories or the server
495 config files. An example of its use might be:
498 <DT><CODE>/foo/.htaccess:</CODE></DT>
499 <DD><CODE>AddHandler server-parsed .html</CODE></DD>
500 <DT><CODE>/foo/bar/.htaccess:</CODE></DT>
501 <DD><CODE>RemoveHandler .html</CODE></DD>
504 This has the effect of returning <SAMP>.html</SAMP> files in the
505 <SAMP>/foo/bar</SAMP> directory to being treated as normal
506 files, rather than as candidates for parsing (see the
507 <A HREF="mod_include.html"><SAMP>mod_include</SAMP></A> module).
511 <H2><A NAME="sethandler">SetHandler</A></H2>
514 HREF="directive-dict.html#Syntax"
516 ><STRONG>Syntax:</STRONG></A> SetHandler <EM>handler-name</EM><BR>
518 HREF="directive-dict.html#Context"
520 ><STRONG>Context:</STRONG></A> directory, .htaccess<BR>
522 HREF="directive-dict.html#Status"
524 ><STRONG>Status:</STRONG></A> Base<BR>
526 HREF="directive-dict.html#Module"
528 ><STRONG>Module:</STRONG></A> mod_mime<BR>
530 HREF="directive-dict.html#Compatibility"
532 ><STRONG>Compatibility:</STRONG></A> SetHandler is only available in Apache
535 <P>When placed into an <CODE>.htaccess</CODE> file or a
536 <CODE><Directory></CODE> or <CODE><Location></CODE> section,
537 this directive forces all matching files to be parsed through the
538 <A HREF="../handler.html">handler</A>
539 given by <EM>handler-name</EM>. For example, if you had a
540 directory you wanted to be parsed entirely as imagemap rule files,
541 regardless of extension, you might put the following into an
542 <CODE>.htaccess</CODE> file in that directory:
547 <P>Another example: if you wanted to have the server display a status
548 report whenever a URL of <CODE>http://servername/status</CODE> was
549 called, you might put the following into access.conf:
551 <Location /status>
552 SetHandler server-status
557 <H2><A NAME="typesconfig">TypesConfig</A></H2>
558 <!--%plaintext <?INDEX {\tt TypesConfig} directive> -->
560 HREF="directive-dict.html#Syntax"
562 ><STRONG>Syntax:</STRONG></A> TypesConfig <EM>filename</EM><BR>
564 HREF="directive-dict.html#Default"
566 ><STRONG>Default:</STRONG></A> <CODE>TypesConfig conf/MIME.types</CODE><BR>
568 HREF="directive-dict.html#Context"
570 ><STRONG>Context:</STRONG></A> server config<BR>
572 HREF="directive-dict.html#Status"
574 ><STRONG>Status:</STRONG></A> Base<BR>
576 HREF="directive-dict.html#Module"
578 ><STRONG>Module:</STRONG></A> mod_mime<P>
580 The TypesConfig directive sets the location of the MIME types configuration
581 file. <EM>Filename</EM> is relative to the
582 <A HREF="core.html#serverroot">ServerRoot</A>. This file sets the default list of
583 mappings from filename extensions to content types; changing this file is not
584 recommended. Use the <A HREF="#addtype">AddType</A> directive instead. The
585 file contains lines in the format of the arguments to an AddType command:
586 <BLOCKQUOTE><EM>MIME-type extension extension ...</EM></BLOCKQUOTE>
587 The extensions are lower-cased. Blank lines, and lines beginning with a hash
588 character (`#') are ignored.<P>
590 <!--#include virtual="footer.html" -->