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 <p>This module provides for determining the types of files
19 from the filename and for association of handlers with files.</p>
22 href="module-dict.html#Status"
24 ><strong>Status:</strong></a> Base
27 href="module-dict.html#SourceFile"
29 ><strong>Source File:</strong></a> mod_mime.c
32 href="module-dict.html#ModuleIdentifier"
34 ><strong>Module Identifier:</strong></a> mime_module
39 This module is used to determine various bits of "meta information"
40 about documents. This information relates to the content of the
41 document and is returned to the browser or used in content-negotiation
42 within the server. In addition, a "handler" can be set for a document,
43 which determines how the document will be processed within the server.
47 The directives <a href="#addcharset">AddCharset</a>,
48 <a href="#addencoding">AddEncoding</a>, <a href="#addhandler">AddHandler</a>,
49 <a href="#addlanguage">AddLanguage</a> and <a href="#addtype">AddType</a>
50 are all used to map file extensions onto the meta-information for that
51 file. Respectively they set the character set, content-encoding, handler,
52 content-language, and MIME-type (content-type) of documents. The
53 directive <a href="#typesconfig">TypesConfig</a> is used to specify a
54 file which also maps extensions onto MIME types. The directives <a
55 href="#forcetype">ForceType</a> and <a
56 href="#sethandler">SetHandler</a> are used to associated all the files
57 in a given location (<em>e.g.</em>, a particular directory) onto a particular
62 Note that changing the type or encoding of a file does not change the
63 value of the <CODE>Last-Modified</code> header. Thus, previously cached
64 copies may still be used by a client or proxy, with the previous headers.
68 <li><a href="#addcharset">AddCharset</a></li>
69 <li><a href="#addencoding">AddEncoding</a>
70 <li><a href="#addhandler">AddHandler</a>
71 <li><a href="#addlanguage">AddLanguage</a>
72 <li><a href="#addtype">AddType</a>
73 <li><a href="#defaultlanguage">DefaultLanguage</a>
74 <li><a href="#forcetype">ForceType</a>
75 <li><a href="#removeencoding">RemoveEncoding</a>
76 <li><a href="#removehandler">RemoveHandler</a>
77 <li><a href="#removetype">RemoveType</a>
78 <li><a href="#sethandler">SetHandler</a>
79 <li><a href="#typesconfig">TypesConfig</a>
83 href="mod_mime_magic.html#mimemagicfile">MimeMagicFile</a>.</p>
85 <h2><a name="multipleext">Files with Multiple Extensions</a></h2>
87 Files can have more than one extension, and the order of the
88 extensions is <em>normally</em> irrelevant. For example, if the file
89 <code>welcome.html.fr</code> maps onto content type text/html and
90 language French then the file <code>welcome.fr.html</code> will map
91 onto exactly the same information. The only exception to this is if an
92 extension is given which Apache does not know how to handle. In this
93 case it will "forget" about any information it obtained from
94 extensions to the left of the unknown extension. So, for example, if
95 the extensions fr and html are mapped to the appropriate language and
96 type but extension xxx is not assigned to anything, then the file
97 <code>welcome.fr.xxx.html</code> will be associated with content-type
98 text/html but <em>no</em> language.
102 If more than one extension is given which maps onto the same type of
103 meta-information, then the one to the right will be used. For example,
104 if ".gif" maps to the MIME-type image/gif and ".html" maps to the
105 MIME-type text/html, then the file <code>welcome.gif.html</code> will
106 be associated with the MIME-type "text/html".
110 Care should be taken when a file with multiple extensions gets
111 associated with both a MIME-type and a handler. This will usually
112 result in the request being by the module associated with the
113 handler. For example, if the <code>.imap</code> extension is mapped to
114 the handler "imap-file" (from mod_imap) and the <code>.html</code>
115 extension is mapped to the MIME-type "text/html", then the file
116 <code>world.imap.html</code> will be associated with both the
117 "imap-file" handler and "text/html" MIME-type. When it is processed,
118 the "imap-file" handler will be used, and so it will be treated as a
119 mod_imap imagemap file.
124 <h2><a name="addcharset">AddCharset</a> directive</h2>
125 <a href="directive-dict.html#Syntax" rel="Help"
126 ><strong>Syntax:</strong></a> AddCharset <em>charset extension</em>
127 [<em>extension</em>] ...<br>
128 <a href="directive-dict.html#Context" rel="Help"
129 ><strong>Context:</strong></a> server config, virtual host, directory, .htaccess<br>
131 href="directive-dict.html#Override"
133 ><strong>Override:</strong></a> FileInfo<br>
135 href="directive-dict.html#Status"
137 ><strong>Status:</strong></a> Base<br>
139 href="directive-dict.html#Module"
141 ><strong>Module:</strong></a> mod_mime
143 <a href="directive-dict.html#Compatibility" rel="Help"
144 ><strong>Compatibility:</strong></a> AddCharset is only available in Apache
148 The AddCharset directive maps the given filename extensions to the
149 specified content charset. <i>charset</i> is the MIME charset
150 parameter of filenames containing <i>extension</i>. This mapping is
151 added to any already in force, overriding any mappings that already
152 exist for the same <i>extension</i>.
158 AddCharset EUC-JP .euc
159 AddCharset ISO-2022-JP .jis
160 AddCharset SHIFT_JIS .sjis
164 Then the document <code>xxxx.ja.jis</code> will be treated as being a
165 Japanese document whose charset is ISO-2022-JP (as will the document
166 <code>xxxx.jis.ja</code>). The AddCharset directive is useful for both
167 to inform the client about the character encoding of the document so
168 that the document can be interpreted and displayed appropriately, and
169 for <a href="../content-negotiation.html">content negotiation</a>, where
170 the server returns one from several documents based on the client's
174 <p>The <em>extension</em> argument is case-insensitive, and can
175 be specified with or without a leading dot.</p>
178 <strong>See also</strong>: <a href="mod_negotiation.html">mod_negotiation</a>
183 <h2><a name="addencoding">AddEncoding</a> directive</h2>
185 href="directive-dict.html#Syntax"
187 ><strong>Syntax:</strong></a> AddEncoding <em>MIME-enc extension</em>
188 [<em>extension</em>] ...<br>
190 href="directive-dict.html#Context"
192 ><strong>Context:</strong></a> server config, virtual host, directory, .htaccess<br>
194 href="directive-dict.html#Override"
196 ><strong>Override:</strong></a> FileInfo<br>
198 href="directive-dict.html#Status"
200 ><strong>Status:</strong></a> Base<br>
202 href="directive-dict.html#Module"
204 ><strong>Module:</strong></a> mod_mime<P>
206 The AddEncoding directive maps the given filename extensions to the
207 specified encoding type. <em>MIME-enc</em> is the MIME encoding to use
208 for documents containing the <em>extension</em>. This mapping is added
209 to any already in force, overriding any mappings that already exist
210 for the same <em>extension</em>.
214 AddEncoding x-gzip .gz<br>
215 AddEncoding x-compress .Z
218 This will cause filenames containing the .gz extension to be marked as
219 encoded using the x-gzip encoding, and filenames containing the .Z
220 extension to be marked as encoded with x-compress.<P>
222 Old clients expect <code>x-gzip</code> and <code>x-compress</code>,
223 however the standard dictates that they're equivalent to <code>gzip</code>
224 and <code>compress</code> respectively. Apache does content encoding
225 comparisons by ignoring any leading <code>x-</code>. When responding
226 with an encoding Apache will use whatever form (<em>i.e.</em>, <code>x-foo</code>
227 or <code>foo</code>) the client requested. If the client didn't
228 specifically request a particular form Apache will use the form given by
229 the <code>AddEncoding</code> directive. To make this long story short,
230 you should always use <code>x-gzip</code> and <code>x-compress</code>
231 for these two specific encodings. More recent encodings, such as
232 <code>deflate</code> should be specified without the <code>x-</code>.
234 <p>The <em>extension</em> argument is case-insensitive, and can
235 be specified with or without a leading dot.</p>
239 <strong>See also</strong>: <a href="#multipleext">Files with
240 multiple extensions</a>
244 <h2><a name="addhandler">AddHandler</a> directive</h2>
247 href="directive-dict.html#Syntax"
249 ><strong>Syntax:</strong></a> AddHandler <em>handler-name extension</em>
250 [<em>extension</em>] ...<br>
252 href="directive-dict.html#Context"
254 ><strong>Context:</strong></a> server config, virtual host, directory, .htaccess<br>
256 href="directive-dict.html#Override"
258 ><strong>Override:</strong></a> FileInfo<br>
260 href="directive-dict.html#Status"
262 ><strong>Status:</strong></a> Base<br>
264 href="directive-dict.html#Module"
266 ><strong>Module:</strong></a> mod_mime<br>
268 href="directive-dict.html#Compatibility"
270 ><strong>Compatibility:</strong></a> AddHandler is only available in Apache
273 <P>AddHandler maps the filename extensions <em>extension</em> to the
274 <a href="../handler.html">handler</a> <em>handler-name</em>. This
275 mapping is added to any already in force, overriding any mappings that
276 already exist for the same <em>extension</em>.
278 For example, to activate CGI scripts
279 with the file extension "<code>.cgi</code>", you might use:
281 AddHandler cgi-script .cgi
284 <P>Once that has been put into your srm.conf or httpd.conf file, any
285 file containing the "<code>.cgi</code>" extension will be treated as a
288 <p>The <em>extension</em> argument is case-insensitive, and can
289 be specified with or without a leading dot.</p>
293 <strong>See also</strong>: <a href="#multipleext">Files with
294 multiple extensions</a>
298 <h2><a name="addlanguage">AddLanguage</a> directive</h2>
300 href="directive-dict.html#Syntax"
302 ><strong>Syntax:</strong></a> AddLanguage <em>MIME-lang extension</em>
303 [<em>extension</em>] ...<br>
305 href="directive-dict.html#Context"
307 ><strong>Context:</strong></a> server config, virtual host, directory, .htaccess<br>
309 href="directive-dict.html#Override"
311 ><strong>Override:</strong></a> FileInfo<br>
313 href="directive-dict.html#Status"
315 ><strong>Status:</strong></a> Base<br>
317 href="directive-dict.html#Module"
319 ><strong>Module:</strong></a> mod_mime
322 The AddLanguage directive maps the given filename extension to the
323 specified content language. <em>MIME-lang</em> is the MIME language of
324 filenames containing <em>extension</em>. This mapping is added to any
325 already in force, overriding any mappings that already exist for the
326 same <em>extension</em>.
332 AddEncoding x-compress .Z<br> AddLanguage en .en<br> AddLanguage fr
333 .fr<br> </code></blockquote>
336 Then the document <code>xxxx.en.Z</code> will be treated as being a
337 compressed English document (as will the document
338 <code>xxxx.Z.en</code>). Although the content language is reported to
339 the client, the browser is unlikely to use this information. The
340 AddLanguage directive is more useful for
341 <a href="../content-negotiation.html">content negotiation</a>, where
342 the server returns one from several documents based on the client's
346 If multiple language assignments are made for the same extension,
347 the last one encountered is the one that is used. That is, for the
352 AddLanguage en-uk .en
353 AddLanguage en-us .en
356 documents with the extension "<code>.en</code>" would be treated as
357 being "<code>en-us</code>".
360 <p>The <em>extension</em> argument is case-insensitive, and can
361 be specified with or without a leading dot.</p>
364 <strong>See also</strong>: <a href="#multipleext">Files with
365 multiple extensions</a>
367 <strong>See also</strong>: <a
368 href="./mod_negotiation.html">mod_negotiation</a>
373 <h2><a name="addtype">AddType</a> directive</h2>
375 href="directive-dict.html#Syntax"
377 ><strong>Syntax:</strong></a> AddType <em>MIME-type extension</em>
378 [<em>extension</em>] ...<br>
380 href="directive-dict.html#Context"
382 ><strong>Context:</strong></a> server config, virtual host, directory, .htaccess<br>
384 href="directive-dict.html#Override"
386 ><strong>Override:</strong></a> FileInfo<br>
388 href="directive-dict.html#Status"
390 ><strong>Status:</strong></a> Base<br>
392 href="directive-dict.html#Module"
394 ><strong>Module:</strong></a> mod_mime<P>
396 The AddType directive maps the given filename extensions onto the
397 specified content type. <em>MIME-type</em> is the MIME type to use for
398 filenames containing <em>extension</em>. This mapping is added to any
399 already in force, overriding any mappings that already exist for the
400 same <em>extension</em>. This directive can be used to add mappings
401 not listed in the MIME types file (see the <code><a
402 href="#typesconfig">TypesConfig</a></code> directive).
406 AddType image/gif .gif
408 It is recommended that new MIME types be added using the AddType directive
409 rather than changing the <a href="#typesconfig">TypesConfig</a> file.<P>
410 Note that, unlike the NCSA httpd, this directive cannot be used to set the
411 type of particular files.<P>
413 <p>The <em>extension</em> argument is case-insensitive, and can
414 be specified with or without a leading dot.</p>
418 <strong>See also</strong>: <a href="#multipleext">Files with
419 multiple extensions</a>
423 <h2><a name="defaultlanguage">DefaultLanguage</a> directive</h2>
425 href="directive-dict.html#Syntax"
427 ><strong>Syntax:</strong></a> DefaultLanguage <em>MIME-lang</em><br>
429 href="directive-dict.html#Context"
431 ><strong>Context:</strong></a> server config, virtual host, directory, .htaccess<br>
433 href="directive-dict.html#Override"
435 ><strong>Override:</strong></a> FileInfo<br>
437 href="directive-dict.html#Status"
439 ><strong>Status:</strong></a> Base<br>
441 href="directive-dict.html#Module"
443 ><strong>Module:</strong></a> mod_mime<br>
445 href="directive-dict.html#Compatibility"
447 ><strong>Compatibility:</strong></a> DefaultLanguage is only available in Apache
450 The DefaultLanguage directive tells Apache that all files in the
451 directive's scope (<em>e.g.</em>, all files covered by the current
452 <code><Directory></code> container) that don't have an explicit
453 language extension (such as <samp>.fr</samp> or <samp>.de</samp> as
454 configured by <samp>AddLanguage</samp>) should be considered to be in
455 the specified <em>MIME-lang</em> language. This allows entire
456 directories to be marked as containing Dutch content, for instance,
457 without having to rename each file. Note that unlike using extensions
458 to specify languages, <samp>DefaultLanguage</samp> can only specify a
463 If no <samp>DefaultLanguage</samp> directive is in force, and a file
464 does not have any language extensions as configured by
465 <samp>AddLanguage</samp>, then that file will be considered to have no
470 <strong>See also</strong>: <a
471 href="./mod_negotiation.html">mod_negotiation</a>
473 <strong>See also</strong>: <a href="#multipleext">Files with
474 multiple extensions</a>
478 <h2><a name="forcetype">ForceType</a> directive</h2>
481 href="directive-dict.html#Syntax"
483 ><strong>Syntax:</strong></a> ForceType <em>media-type</em><br>
485 href="directive-dict.html#Context"
487 ><strong>Context:</strong></a> directory, .htaccess<br>
489 href="directive-dict.html#Status"
491 ><strong>Status:</strong></a> Base<br>
493 href="directive-dict.html#Module"
495 ><strong>Module:</strong></a> mod_mime<br>
497 href="directive-dict.html#Compatibility"
499 ><strong>Compatibility:</strong></a> ForceType is only available in Apache
502 <P>When placed into an <code>.htaccess</code> file or a
503 <code><Directory></code> or <code><Location></code> section,
504 this directive forces all matching files to be served
505 as the content type given by <em>media type</em>. For example, if you
506 had a directory full of GIF files, but did not want to label them all with
507 ".gif", you might want to use:
511 <P>Note that this will override any filename extensions that might determine
512 the media type.</P><hr>
514 <h2><a name="removeencoding">RemoveEncoding</a> directive</h2>
517 href="directive-dict.html#Syntax"
519 ><strong>Syntax:</strong></a> RemoveEncoding <em>extension</em>
520 [<em>extension</em>] ...<br>
522 href="directive-dict.html#Context"
524 ><strong>Context:</strong></a> directory, .htaccess<br>
526 href="directive-dict.html#Status"
528 ><strong>Status:</strong></a> Base<br>
530 href="directive-dict.html#Module"
532 ><strong>Module:</strong></a> mod_mime<br>
534 href="directive-dict.html#Compatibility"
536 ><strong>Compatibility:</strong></a> RemoveEncoding is only available in Apache
540 The <samp>RemoveEncoding</samp> directive removes any
541 encoding associations for files with the given extensions.
542 This allows <code>.htaccess</code> files in subdirectories to undo
543 any associations inherited from parent directories or the server
544 config files. An example of its use might be:
547 <DT><code>/foo/.htaccess:</code></DT>
548 <DD><code>AddEncoding x-gzip .gz</code>
550 <code>AddType text/plain .asc</code>
552 <code><Files *.gz.asc></code>
554 <code> RemoveEncoding .gz</code>
556 <code></Files></code></dd>
559 This will cause <code>foo.gz</code> to mark as being encoded with the
560 gzip method, but <code>foo.gz.asc</code> as an unencoded plaintext file.
563 <b>Note:</b>RemoveEncoding directives are processed <i>after</i> any
564 AddEncoding directives, so it is possible they may undo the effects
565 of the latter if both occur within the same directory configuration.
567 <p>The <em>extension</em> argument is case-insensitive, and can
568 be specified with or without a leading dot.</p>
572 <h2><a name="removehandler">RemoveHandler</a> directive</h2>
575 href="directive-dict.html#Syntax"
577 ><strong>Syntax:</strong></a> RemoveHandler <em>extension</em>
578 [<em>extension</em>] ...<br>
580 href="directive-dict.html#Context"
582 ><strong>Context:</strong></a> directory, .htaccess<br>
584 href="directive-dict.html#Status"
586 ><strong>Status:</strong></a> Base<br>
588 href="directive-dict.html#Module"
590 ><strong>Module:</strong></a> mod_mime<br>
592 href="directive-dict.html#Compatibility"
594 ><strong>Compatibility:</strong></a> RemoveHandler is only available in Apache
598 The <samp>RemoveHandler</samp> directive removes any
599 handler associations for files with the given extensions.
600 This allows <code>.htaccess</code> files in subdirectories to undo
601 any associations inherited from parent directories or the server
602 config files. An example of its use might be:
605 <dt><code>/foo/.htaccess:</code></dt>
606 <dd><code>AddHandler server-parsed .html</code></dd>
607 <dt><code>/foo/bar/.htaccess:</code></dt>
608 <dd><code>RemoveHandler .html</code></dd>
611 This has the effect of returning <samp>.html</samp> files in the
612 <samp>/foo/bar</samp> directory to being treated as normal
613 files, rather than as candidates for parsing (see the
614 <a href="mod_include.html"><samp>mod_include</samp></a> module).
616 <p>The <em>extension</em> argument is case-insensitive, and can
617 be specified with or without a leading dot.</p>
621 <h2><a name="removetype">RemoveType</a> directive</h2>
624 href="directive-dict.html#Syntax"
626 ><strong>Syntax:</strong></a> RemoveType <em>extension</em>
627 [<em>extension</em>] ...<br>
629 href="directive-dict.html#Context"
631 ><strong>Context:</strong></a> directory, .htaccess<br>
633 href="directive-dict.html#Status"
635 ><strong>Status:</strong></a> Base<br>
637 href="directive-dict.html#Module"
639 ><strong>Module:</strong></a> mod_mime<br>
641 href="directive-dict.html#Compatibility"
643 ><strong>Compatibility:</strong></a> RemoveType is only available in Apache
647 The <samp>RemoveType</samp> directive removes any
648 MIME type associations for files with the given extensions.
649 This allows <code>.htaccess</code> files in subdirectories to undo
650 any associations inherited from parent directories or the server
651 config files. An example of its use might be:
654 <dt><code>/foo/.htaccess:</code></dt>
655 <dd><code>RemoveType .cgi</code></dd>
658 This will remove any special handling of <code>.cgi</code> files in the
659 <code>/foo/</code> directory and any beneath it, causing the files to be
660 treated as being of the <a href="core.html#defaulttype">default type</a>.
663 <b>Note:</b><code>RemoveType</code> directives are processed <i>after</i> any
664 <code>AddType</code> directives, so it is possible they may undo the effects
665 of the latter if both occur within the same directory configuration.
667 <p>The <em>extension</em> argument is case-insensitive, and can
668 be specified with or without a leading dot.</p>
672 <h2><a name="sethandler">SetHandler</a> directive</h2>
675 href="directive-dict.html#Syntax"
677 ><strong>Syntax:</strong></a> SetHandler <em>handler-name</em><br>
679 href="directive-dict.html#Context"
681 ><strong>Context:</strong></a> directory, .htaccess<br>
683 href="directive-dict.html#Status"
685 ><strong>Status:</strong></a> Base<br>
687 href="directive-dict.html#Module"
689 ><strong>Module:</strong></a> mod_mime<br>
691 href="directive-dict.html#Compatibility"
693 ><strong>Compatibility:</strong></a> SetHandler is only available in Apache
696 <P>When placed into an <code>.htaccess</code> file or a
697 <code><Directory></code> or <code><Location></code> section,
698 this directive forces all matching files to be parsed through the
699 <a href="../handler.html">handler</a>
700 given by <em>handler-name</em>. For example, if you had a
701 directory you wanted to be parsed entirely as imagemap rule files,
702 regardless of extension, you might put the following into an
703 <code>.htaccess</code> file in that directory:
708 <P>Another example: if you wanted to have the server display a status
709 report whenever a URL of <code>http://servername/status</code> was
710 called, you might put the following into access.conf:
712 <Location /status>
713 SetHandler server-status
718 <h2><a name="typesconfig">TypesConfig</a> directive</h2>
720 href="directive-dict.html#Syntax"
722 ><strong>Syntax:</strong></a> TypesConfig <em>file-path</em><br>
724 href="directive-dict.html#Default"
726 ><strong>Default:</strong></a> <code>TypesConfig conf/mime.types</code><br>
728 href="directive-dict.html#Context"
730 ><strong>Context:</strong></a> server config<br>
732 href="directive-dict.html#Status"
734 ><strong>Status:</strong></a> Base<br>
736 href="directive-dict.html#Module"
738 ><strong>Module:</strong></a> mod_mime<P>
740 The TypesConfig directive sets the location of the MIME types configuration
741 file. <em>Filename</em> is relative to the
742 <a href="core.html#serverroot">ServerRoot</a>. This file sets the default list of
743 mappings from filename extensions to content types; changing this file is not
744 recommended. Use the <a href="#addtype">AddType</a> directive instead. The
745 file contains lines in the format of the arguments to an AddType command:
746 <blockquote><em>MIME-type extension extension ...</em></blockquote>
747 The extensions are lower-cased. Blank lines, and lines beginning with a hash
748 character (`#') are ignored.<P>
750 <!--#include virtual="footer.html" -->