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 <A NAME="multipleext"><H2>Files with Multiple Extensions</H2></A>
53 Files can have more than one extension, and the order of the
54 extensions is <i>normally</i> 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="#sethandler">SetHandler</A>
96 <LI><A HREF="#typesconfig">TypesConfig</A>
101 <H2><A NAME="addencoding">AddEncoding</A></H2>
102 <!--%plaintext <?INDEX {\tt AddEncoding} directive> -->
104 HREF="directive-dict.html#Syntax"
106 ><STRONG>Syntax:</STRONG></A> AddEncoding <EM>MIME-enc extension extension...</EM><BR>
108 HREF="directive-dict.html#Context"
110 ><STRONG>Context:</STRONG></A> server config, virtual host, directory, .htaccess<BR>
112 HREF="directive-dict.html#Override"
114 ><STRONG>Override:</STRONG></A> FileInfo<BR>
116 HREF="directive-dict.html#Status"
118 ><STRONG>Status:</STRONG></A> Base<BR>
120 HREF="directive-dict.html#Module"
122 ><STRONG>Module:</STRONG></A> mod_mime<P>
124 The AddEncoding directive maps the given filename extensions to the
125 specified encoding type. <EM>MIME-enc</EM> is the MIME encoding to use
126 for documents containing the <EM>extension</EM>. This mapping is added
127 to any already in force, overriding any mappings that already exist
128 for the same <EM>extension</EM>.
131 <BLOCKQUOTE><CODE> AddEncoding x-gzip gz<BR> AddEncoding x-compress Z
134 This will cause filenames containing the .gz extension to be marked as
135 encoded using the x-gzip encoding, and filenames containing the .Z
136 extension to be marked as encoded with x-compress.<P>
138 Old clients expect <CODE>x-gzip</CODE> and <CODE>x-compress</CODE>,
139 however the standard dictates that they're equivalent to <CODE>gzip</CODE>
140 and <CODE>compress</CODE> respectively. Apache does content encoding
141 comparisons by ignoring any leading <CODE>x-</CODE>. When responding
142 with an encoding Apache will use whatever form (<EM>i.e.</EM>, <CODE>x-foo</CODE>
143 or <CODE>foo</CODE>) the client requested. If the client didn't
144 specifically request a particular form Apache will use the form given by
145 the <CODE>AddEncoding</CODE> directive. To make this long story short,
146 you should always use <CODE>x-gzip</CODE> and <CODE>x-compress</CODE>
147 for these two specific encodings. More recent encodings, such as
148 <CODE>deflate</CODE> should be specified without the <CODE>x-</CODE>.
152 <STRONG>See also</STRONG>: <A HREF="#multipleext">Files with
153 multiple extensions</A>
157 <H2><A NAME="addhandler">AddHandler</A></H2>
160 HREF="directive-dict.html#Syntax"
162 ><STRONG>Syntax:</STRONG></A> AddHandler <EM>handler-name 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<BR>
180 HREF="directive-dict.html#Compatibility"
182 ><STRONG>Compatibility:</STRONG></A> AddHandler is only available in Apache
185 <P>AddHandler maps the filename extensions <EM>extension</EM> to the
186 <A HREF="../handler.html">handler</A> <EM>handler-name</EM>. This
187 mapping is added to any already in force, overriding any mappings that
188 already exist for the same <EM>extension</EM>.
190 For example, to activate CGI scripts
191 with the file extension "<CODE>.cgi</CODE>", you might use:
193 AddHandler cgi-script cgi
196 <P>Once that has been put into your srm.conf or httpd.conf file, any
197 file containing the "<CODE>.cgi</CODE>" extension will be treated as a
202 <STRONG>See also</STRONG>: <A HREF="#multipleext">Files with
203 multiple extensions</A>
207 <H2><A NAME="addlanguage">AddLanguage</A></H2>
208 <!--%plaintext <?INDEX {\tt AddLanguage} directive> -->
210 HREF="directive-dict.html#Syntax"
212 ><STRONG>Syntax:</STRONG></A> AddLanguage <EM>MIME-lang extension extension...</EM><BR>
214 HREF="directive-dict.html#Context"
216 ><STRONG>Context:</STRONG></A> server config, virtual host, directory, .htaccess<BR>
218 HREF="directive-dict.html#Override"
220 ><STRONG>Override:</STRONG></A> FileInfo<BR>
222 HREF="directive-dict.html#Status"
224 ><STRONG>Status:</STRONG></A> Base<BR>
226 HREF="directive-dict.html#Module"
228 ><STRONG>Module:</STRONG></A> mod_mime<P>
230 The AddLanguage directive maps the given filename extensions to the
231 specified content language. <EM>MIME-lang</EM> is the MIME language of
232 filenames containing <EM>extension</EM>. This mapping is added to any
233 already in force, overriding any mappings that already exist for the
234 same <EM>extension</EM>.
236 Example: <BLOCKQUOTE><CODE>
237 AddEncoding x-compress Z<BR> AddLanguage en .en<BR> AddLanguage fr
238 .fr<BR> </CODE></BLOCKQUOTE>
240 Then the document <CODE>xxxx.en.Z</CODE> will be treated as being a
241 compressed English document (as will the document
242 <CODE>xxxx.Z.en</CODE>). Although the content language is reported to
243 the client, the browser is unlikely to use this information. The
244 AddLanguage directive is more useful for content negotiation, where
245 the server returns one from several documents based on the client's
246 language preference.<P>
250 <STRONG>See also</STRONG>: <A HREF="#multipleext">Files with
251 multiple extensions</A>
255 <H2><A NAME="addtype">AddType</A></H2>
256 <!--%plaintext <?INDEX {\tt AddType} directive> -->
258 HREF="directive-dict.html#Syntax"
260 ><STRONG>Syntax:</STRONG></A> AddType <EM>MIME-type extension extension...</EM><BR>
262 HREF="directive-dict.html#Context"
264 ><STRONG>Context:</STRONG></A> server config, virtual host, directory, .htaccess<BR>
266 HREF="directive-dict.html#Override"
268 ><STRONG>Override:</STRONG></A> FileInfo<BR>
270 HREF="directive-dict.html#Status"
272 ><STRONG>Status:</STRONG></A> Base<BR>
274 HREF="directive-dict.html#Module"
276 ><STRONG>Module:</STRONG></A> mod_mime<P>
278 The AddType directive maps the given filename extensions onto the
279 specified content type. <EM>MIME-enc</EM> is the MIME type to use for
280 filenames containing <EM>extension</EM>. This mapping is added to any
281 already in force, overriding any mappings that already exist for the
282 same <EM>extension</EM>. This directive can be used to add mappings
283 not listed in the MIME types file (see the <CODE><A
284 HREF="#typesconfig">TypesConfig</A></CODE> directive).
288 AddType image/gif GIF
290 It is recommended that new MIME types be added using the AddType directive
291 rather than changing the <A HREF="#typesconfig">TypesConfig</A> file.<P>
292 Note that, unlike the NCSA httpd, this directive cannot be used to set the
293 type of particular files.<P>
297 <STRONG>See also</STRONG>: <A HREF="#multipleext">Files with
298 multiple extensions</A>
302 <H2><A NAME="defaultlanguage">DefaultLanguage</A></H2>
303 <!--%plaintext <?INDEX {\tt DefaultLanguage} directive> -->
305 HREF="directive-dict.html#Syntax"
307 ><STRONG>Syntax:</STRONG></A> DefaultLanguage <EM>MIME-lang</EM><BR>
309 HREF="directive-dict.html#Context"
311 ><STRONG>Context:</STRONG></A> server config, virtual host, directory, .htaccess<BR>
313 HREF="directive-dict.html#Override"
315 ><STRONG>Override:</STRONG></A> FileInfo<BR>
317 HREF="directive-dict.html#Status"
319 ><STRONG>Status:</STRONG></A> Base<BR>
321 HREF="directive-dict.html#Module"
323 ><STRONG>Module:</STRONG></A> mod_mime<P>
325 The DefaultLanguage directive tells Apache that all files in the
326 directive's scope (<EM>e.g.</EM>, all files covered by the current
327 <CODE><Directory></CODE> container) that don't have an explicit language
328 extension (such as <SAMP>.fr</SAMP> or <SAMP>.de</SAMP>) should be
329 considered to be the specified <EM>MIME-lang</EM> language
330 by default, rather than English. This allows entire directories
331 to be marked as containing Dutch content, for instance, without
332 having to rename each file.
336 <STRONG>See also</STRONG>: <A HREF="#multipleext">Files with
337 multiple extensions</A>
341 <H2><A NAME="forcetype">ForceType</A></H2>
344 HREF="directive-dict.html#Syntax"
346 ><STRONG>Syntax:</STRONG></A> ForceType <EM>media type</EM><BR>
348 HREF="directive-dict.html#Context"
350 ><STRONG>Context:</STRONG></A> directory, .htaccess<BR>
352 HREF="directive-dict.html#Status"
354 ><STRONG>Status:</STRONG></A> Base<BR>
356 HREF="directive-dict.html#Module"
358 ><STRONG>Module:</STRONG></A> mod_mime<BR>
360 HREF="directive-dict.html#Compatibility"
362 ><STRONG>Compatibility:</STRONG></A> ForceType is only available in Apache
365 <P>When placed into an <CODE>.htaccess</CODE> file or a
366 <CODE><Directory></CODE> or <CODE><Location></CODE> section,
367 this directive forces all matching files to be served
368 as the content type given by <EM>media type</EM>. For example, if you
369 had a directory full of GIF files, but did not want to label them all with
370 ".gif", you might want to use:
374 <P>Note that this will override any filename extensions that might determine
375 the media type.</P><HR>
377 <H2><A NAME="sethandler">SetHandler</A></H2>
380 HREF="directive-dict.html#Syntax"
382 ><STRONG>Syntax:</STRONG></A> SetHandler <EM>handler-name</EM><BR>
384 HREF="directive-dict.html#Context"
386 ><STRONG>Context:</STRONG></A> directory, .htaccess<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<BR>
396 HREF="directive-dict.html#Compatibility"
398 ><STRONG>Compatibility:</STRONG></A> SetHandler is only available in Apache
401 <P>When placed into an <CODE>.htaccess</CODE> file or a
402 <CODE><Directory></CODE> or <CODE><Location></CODE> section,
403 this directive forces all matching files to be parsed through the
404 <A HREF="../handler.html">handler</A>
405 given by <EM>handler-name</EM>. For example, if you had a
406 directory you wanted to be parsed entirely as imagemap rule files,
407 regardless of extension, you might put the following into an
408 <CODE>.htaccess</CODE> file in that directory:
413 <P>Another example: if you wanted to have the server display a status
414 report whenever a URL of <CODE>http://servername/status</CODE> was
415 called, you might put the following into access.conf:
417 <Location /status>
418 SetHandler server-status
423 <H2><A NAME="typesconfig">TypesConfig</A></H2>
424 <!--%plaintext <?INDEX {\tt TypesConfig} directive> -->
426 HREF="directive-dict.html#Syntax"
428 ><STRONG>Syntax:</STRONG></A> TypesConfig <EM>filename</EM><BR>
430 HREF="directive-dict.html#Default"
432 ><STRONG>Default:</STRONG></A> <CODE>TypesConfig conf/MIME.types</CODE><BR>
434 HREF="directive-dict.html#Context"
436 ><STRONG>Context:</STRONG></A> server config<BR>
438 HREF="directive-dict.html#Status"
440 ><STRONG>Status:</STRONG></A> Base<BR>
442 HREF="directive-dict.html#Module"
444 ><STRONG>Module:</STRONG></A> mod_mime<P>
446 The TypesConfig directive sets the location of the MIME types configuration
447 file. <EM>Filename</EM> is relative to the
448 <A HREF="core.html#serverroot">ServerRoot</A>. This file sets the default list of
449 mappings from filename extensions to content types; changing this file is not
450 recommended. Use the <A HREF="#addtype">AddType</A> directive instead. The
451 file contains lines in the format of the arguments to an AddType command:
452 <BLOCKQUOTE><EM>MIME-type extension extension ...</EM></BLOCKQUOTE>
453 The extensions are lower-cased. Blank lines, and lines beginning with a hash
454 character (`#') are ignored.<P>
456 <!--#include virtual="footer.html" -->