]> granicus.if.org Git - apache/blob - docs/manual/mod/mod_mime.html
The semi-occasional partial cleaning-up of the HTML..
[apache] / docs / manual / mod / mod_mime.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
2 <HTML>
3 <HEAD>
4 <TITLE>Apache module mod_mime</TITLE>
5 </HEAD>
6
7 <!-- Background white, links blue (unvisited), navy (visited), red (active) -->
8 <BODY
9  BGCOLOR="#FFFFFF"
10  TEXT="#000000"
11  LINK="#0000FF"
12  VLINK="#000080"
13  ALINK="#FF0000"
14 >
15 <!--#include virtual="header.html" -->
16 <H1 ALIGN="CENTER">Module mod_mime</H1>
17
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
20 from the filename.
21
22 <H2>Summary</H2>
23
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.
29
30 <P>
31
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
43 MIME type or handler.
44
45 <P>
46
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.
50
51 <H2><A NAME="multipleext">Files with Multiple Extensions</A></H2>
52
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.
65
66 <P>
67
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".
73
74 <P>
75
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.
86
87 <H2>Directives</H2>
88 <UL>
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>
98 </UL>
99 <HR>
100
101
102 <H2><A NAME="addencoding">AddEncoding</A></H2>
103 <!--%plaintext &lt;?INDEX {\tt AddEncoding} directive&gt; -->
104 <A
105  HREF="directive-dict.html#Syntax"
106  REL="Help"
107 ><STRONG>Syntax:</STRONG></A> AddEncoding <EM>MIME-enc extension extension...</EM><BR>
108 <A
109  HREF="directive-dict.html#Context"
110  REL="Help"
111 ><STRONG>Context:</STRONG></A> server config, virtual host, directory, .htaccess<BR>
112 <A
113  HREF="directive-dict.html#Override"
114  REL="Help"
115 ><STRONG>Override:</STRONG></A> FileInfo<BR>
116 <A
117  HREF="directive-dict.html#Status"
118  REL="Help"
119 ><STRONG>Status:</STRONG></A> Base<BR>
120 <A
121  HREF="directive-dict.html#Module"
122  REL="Help"
123 ><STRONG>Module:</STRONG></A> mod_mime<P>
124
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>.
130
131 Example:
132 <BLOCKQUOTE><CODE> AddEncoding x-gzip gz<BR> AddEncoding x-compress Z
133 </CODE></BLOCKQUOTE>
134
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>
138
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>.
150
151 <P>
152
153 <STRONG>See also</STRONG>: <A HREF="#multipleext">Files with
154 multiple extensions</A>
155
156 <P><HR>
157
158 <H2><A NAME="addhandler">AddHandler</A></H2>
159
160 <A
161  HREF="directive-dict.html#Syntax"
162  REL="Help"
163 ><STRONG>Syntax:</STRONG></A> AddHandler <EM>handler-name extension extension...</EM><BR>
164 <A
165  HREF="directive-dict.html#Context"
166  REL="Help"
167 ><STRONG>Context:</STRONG></A> server config, virtual host, directory, .htaccess<BR>
168 <A
169  HREF="directive-dict.html#Override"
170  REL="Help"
171 ><STRONG>Override:</STRONG></A> FileInfo<BR>
172 <A
173  HREF="directive-dict.html#Status"
174  REL="Help"
175 ><STRONG>Status:</STRONG></A> Base<BR>
176 <A
177  HREF="directive-dict.html#Module"
178  REL="Help"
179 ><STRONG>Module:</STRONG></A> mod_mime<BR>
180 <A
181  HREF="directive-dict.html#Compatibility"
182  REL="Help"
183 ><STRONG>Compatibility:</STRONG></A> AddHandler is only available in Apache
184 1.1 and later<P>
185
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>.
190
191 For example, to activate CGI scripts
192 with the file extension "<CODE>.cgi</CODE>", you might use:
193 <PRE>
194     AddHandler cgi-script cgi
195 </PRE>
196
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
199 CGI program.</P> 
200
201 <P>
202
203 <STRONG>See also</STRONG>: <A HREF="#multipleext">Files with
204 multiple extensions</A>
205
206 <HR>
207
208 <H2><A NAME="addlanguage">AddLanguage</A></H2>
209 <!--%plaintext &lt;?INDEX {\tt AddLanguage} directive&gt; -->
210 <A
211  HREF="directive-dict.html#Syntax"
212  REL="Help"
213 ><STRONG>Syntax:</STRONG></A> AddLanguage <EM>MIME-lang extension extension...</EM><BR>
214 <A
215  HREF="directive-dict.html#Context"
216  REL="Help"
217 ><STRONG>Context:</STRONG></A> server config, virtual host, directory, .htaccess<BR>
218 <A
219  HREF="directive-dict.html#Override"
220  REL="Help"
221 ><STRONG>Override:</STRONG></A> FileInfo<BR>
222 <A
223  HREF="directive-dict.html#Status"
224  REL="Help"
225 ><STRONG>Status:</STRONG></A> Base<BR>
226 <A
227  HREF="directive-dict.html#Module"
228  REL="Help"
229 ><STRONG>Module:</STRONG></A> mod_mime<P>
230
231 The AddLanguage directive maps the given filename extensions to the
232 specified content language. <EM>MIME-lang</EM> is the MIME language of
233 filenames containing <EM>extension</EM>.  This mapping is added to any
234 already in force, overriding any mappings that already exist for the
235 same <EM>extension</EM>.
236
237 Example: <BLOCKQUOTE><CODE>
238 AddEncoding x-compress Z<BR> AddLanguage en .en<BR> AddLanguage fr
239 .fr<BR> </CODE></BLOCKQUOTE>
240
241 Then the document <CODE>xxxx.en.Z</CODE> will be treated as being a
242 compressed English document (as will the document
243 <CODE>xxxx.Z.en</CODE>). Although the content language is reported to
244 the client, the browser is unlikely to use this information. The
245 AddLanguage directive is more useful for <A
246 HREF="../content-negotiation.html">content negotiation</A>, where
247 the server returns one from several documents based on the client's
248 language preference.<P>
249
250 <P>
251
252 <STRONG>See also</STRONG>: <A HREF="#multipleext">Files with
253 multiple extensions</A>
254 <BR>
255 <STRONG>See also</STRONG>: <A
256 HREF="./mod_negotiation.html">mod_negotiation</A>
257
258 <HR>
259
260 <H2><A NAME="addtype">AddType</A></H2>
261 <!--%plaintext &lt;?INDEX {\tt AddType} directive&gt; -->
262 <A
263  HREF="directive-dict.html#Syntax"
264  REL="Help"
265 ><STRONG>Syntax:</STRONG></A> AddType <EM>MIME-type extension extension...</EM><BR>
266 <A
267  HREF="directive-dict.html#Context"
268  REL="Help"
269 ><STRONG>Context:</STRONG></A> server config, virtual host, directory, .htaccess<BR>
270 <A
271  HREF="directive-dict.html#Override"
272  REL="Help"
273 ><STRONG>Override:</STRONG></A> FileInfo<BR>
274 <A
275  HREF="directive-dict.html#Status"
276  REL="Help"
277 ><STRONG>Status:</STRONG></A> Base<BR>
278 <A
279  HREF="directive-dict.html#Module"
280  REL="Help"
281 ><STRONG>Module:</STRONG></A> mod_mime<P>
282
283 The AddType directive maps the given filename extensions onto the
284 specified content type. <EM>MIME-enc</EM> is the MIME type to use for
285 filenames containing <EM>extension</EM>.  This mapping is added to any
286 already in force, overriding any mappings that already exist for the
287 same <EM>extension</EM>. This directive can be used to add mappings
288 not listed in the MIME types file (see the <CODE><A
289 HREF="#typesconfig">TypesConfig</A></CODE> directive).
290
291 Example:
292 <BLOCKQUOTE><CODE>
293 AddType image/gif GIF
294 </CODE></BLOCKQUOTE>
295 It is recommended that new MIME types be added using the AddType directive
296 rather than changing the <A HREF="#typesconfig">TypesConfig</A> file.<P>
297 Note that, unlike the NCSA httpd, this directive cannot be used to set the
298 type of particular files.<P>
299
300 <P>
301
302 <STRONG>See also</STRONG>: <A HREF="#multipleext">Files with
303 multiple extensions</A>
304
305 <HR>
306
307 <H2><A NAME="defaultlanguage">DefaultLanguage</A></H2>
308 <!--%plaintext &lt;?INDEX {\tt DefaultLanguage} directive&gt; -->
309 <A
310  HREF="directive-dict.html#Syntax"
311  REL="Help"
312 ><STRONG>Syntax:</STRONG></A> DefaultLanguage <EM>MIME-lang</EM><BR>
313 <A
314  HREF="directive-dict.html#Context"
315  REL="Help"
316 ><STRONG>Context:</STRONG></A> server config, virtual host, directory, .htaccess<BR>
317 <A
318  HREF="directive-dict.html#Override"
319  REL="Help"
320 ><STRONG>Override:</STRONG></A> FileInfo<BR>
321 <A
322  HREF="directive-dict.html#Status"
323  REL="Help"
324 ><STRONG>Status:</STRONG></A> Base<BR>
325 <A
326  HREF="directive-dict.html#Module"
327  REL="Help"
328 ><STRONG>Module:</STRONG></A> mod_mime<P>
329
330 The DefaultLanguage directive tells Apache that all files in the
331 directive's scope (<EM>e.g.</EM>, all files covered by the current
332 <CODE>&lt;Directory&gt;</CODE> container) that don't have an explicit
333 language extension (such as <SAMP>.fr</SAMP> or <SAMP>.de</SAMP> as
334 configured by <SAMP>AddLanguage</SAMP>) should be considered to be in
335 the specified <EM>MIME-lang</EM> language.  This allows entire
336 directories to be marked as containing Dutch content, for instance,
337 without having to rename each file. Note that unlike using extensions
338 to specify languages, <SAMP>DefaultLanguage</SAMP> can only specify a
339 single language.
340
341 <P>
342
343 If no <SAMP>DefaultLanguage</SAMP> directive is in force, and a file
344 does not have any language extensions as configured by
345 <SAMP>AddLanguage</SAMP>, then that file will be considered to have no
346 language attribute.
347
348 <P>
349
350 <STRONG>See also</STRONG>: <A
351 HREF="./mod_negotiation.html">mod_negotiation</A>
352 <BR>
353 <STRONG>See also</STRONG>: <A HREF="#multipleext">Files with
354 multiple extensions</A>
355
356 <HR>
357
358 <H2><A NAME="forcetype">ForceType</A></H2>
359
360 <A
361  HREF="directive-dict.html#Syntax"
362  REL="Help"
363 ><STRONG>Syntax:</STRONG></A> ForceType <EM>media type</EM><BR>
364 <A
365  HREF="directive-dict.html#Context"
366  REL="Help"
367 ><STRONG>Context:</STRONG></A> directory, .htaccess<BR>
368 <A
369  HREF="directive-dict.html#Status"
370  REL="Help"
371 ><STRONG>Status:</STRONG></A> Base<BR>
372 <A
373  HREF="directive-dict.html#Module"
374  REL="Help"
375 ><STRONG>Module:</STRONG></A> mod_mime<BR>
376 <A
377  HREF="directive-dict.html#Compatibility"
378  REL="Help"
379 ><STRONG>Compatibility:</STRONG></A> ForceType is only available in Apache
380 1.1 and later.<P>
381
382 <P>When placed into an <CODE>.htaccess</CODE> file or a
383 <CODE>&lt;Directory&gt;</CODE> or <CODE>&lt;Location&gt;</CODE> section,
384 this directive forces all matching files to be served
385 as the content type given by <EM>media type</EM>. For example, if you
386 had a directory full of GIF files, but did not want to label them all with
387 ".gif", you might want to use:
388 <PRE>
389     ForceType image/gif
390 </PRE>
391 <P>Note that this will override any filename extensions that might determine
392 the media type.</P><HR>
393
394 <H2><A NAME="removehandler">RemoveHandler</A></H2>
395
396 <A
397  HREF="directive-dict.html#Syntax"
398  REL="Help"
399 ><STRONG>Syntax:</STRONG></A> RemoveHandler <EM>extension extension...</EM><BR>
400 <A
401  HREF="directive-dict.html#Context"
402  REL="Help"
403 ><STRONG>Context:</STRONG></A> directory, .htaccess<BR>
404 <A
405  HREF="directive-dict.html#Status"
406  REL="Help"
407 ><STRONG>Status:</STRONG></A> Base<BR>
408 <A
409  HREF="directive-dict.html#Module"
410  REL="Help"
411 ><STRONG>Module:</STRONG></A> mod_mime<BR>
412 <A
413  HREF="directive-dict.html#Compatibility"
414  REL="Help"
415 ><STRONG>Compatibility:</STRONG></A> RemoveHandler is only available in Apache
416 1.3.4 and later.<P>
417
418 <P>
419 The <SAMP>RemoveHandler</SAMP> directive removes any
420 handler associations for files with the given extensions.
421 This allows <CODE>.htaccess</CODE> files in subdirectories to undo
422 any associations inherited from parent directories or the server
423 config files.  An example of its use might be:
424 </P>
425 <DL>
426  <DT><CODE>/foo/.htaccess:</CODE></DT>
427  <DD><CODE>AddHandler server-parsed .html</CODE></DD>
428  <DT><CODE>/foo/bar/.htaccess:</CODE></DT>
429  <DD><CODE>RemoveHandler .html</CODE></DD>
430 </DL>
431 <P>
432 This has the effect of returning <SAMP>.html</SAMP> files in the
433 <SAMP>/foo/bar</SAMP> directory to being treated as normal
434 files, rather than as candidates for parsing (see the
435 <A HREF="mod_include.html"><SAMP>mod_include</SAMP></A> module).
436 </P>
437 <HR>
438
439 <H2><A NAME="sethandler">SetHandler</A></H2>
440
441 <A
442  HREF="directive-dict.html#Syntax"
443  REL="Help"
444 ><STRONG>Syntax:</STRONG></A> SetHandler <EM>handler-name</EM><BR>
445 <A
446  HREF="directive-dict.html#Context"
447  REL="Help"
448 ><STRONG>Context:</STRONG></A> directory, .htaccess<BR>
449 <A
450  HREF="directive-dict.html#Status"
451  REL="Help"
452 ><STRONG>Status:</STRONG></A> Base<BR>
453 <A
454  HREF="directive-dict.html#Module"
455  REL="Help"
456 ><STRONG>Module:</STRONG></A> mod_mime<BR>
457 <A
458  HREF="directive-dict.html#Compatibility"
459  REL="Help"
460 ><STRONG>Compatibility:</STRONG></A> SetHandler is only available in Apache
461 1.1 and later.<P>
462
463 <P>When placed into an <CODE>.htaccess</CODE> file or a
464 <CODE>&lt;Directory&gt;</CODE> or <CODE>&lt;Location&gt;</CODE> section,
465 this directive forces all matching files to be parsed through the
466 <A HREF="../handler.html">handler</A>
467 given by <EM>handler-name</EM>. For example, if you had a
468 directory you wanted to be parsed entirely as imagemap rule files,
469 regardless of extension, you might put the following into an
470 <CODE>.htaccess</CODE> file in that directory:
471 <PRE>
472     SetHandler imap-file
473 </PRE>
474
475 <P>Another example: if you wanted to have the server display a status
476 report whenever a URL of <CODE>http://servername/status</CODE> was
477 called, you might put the following into access.conf:
478 <PRE>
479     &lt;Location /status&gt;
480     SetHandler server-status
481     &lt;/Location&gt;
482 </PRE>
483 <HR>
484
485 <H2><A NAME="typesconfig">TypesConfig</A></H2>
486 <!--%plaintext &lt;?INDEX {\tt TypesConfig} directive&gt; -->
487 <A
488  HREF="directive-dict.html#Syntax"
489  REL="Help"
490 ><STRONG>Syntax:</STRONG></A> TypesConfig <EM>filename</EM><BR>
491 <A
492  HREF="directive-dict.html#Default"
493  REL="Help"
494 ><STRONG>Default:</STRONG></A> <CODE>TypesConfig conf/MIME.types</CODE><BR>
495 <A
496  HREF="directive-dict.html#Context"
497  REL="Help"
498 ><STRONG>Context:</STRONG></A> server config<BR>
499 <A
500  HREF="directive-dict.html#Status"
501  REL="Help"
502 ><STRONG>Status:</STRONG></A> Base<BR>
503 <A
504  HREF="directive-dict.html#Module"
505  REL="Help"
506 ><STRONG>Module:</STRONG></A> mod_mime<P>
507
508 The TypesConfig directive sets the location of the MIME types configuration
509 file. <EM>Filename</EM> is relative to the
510 <A HREF="core.html#serverroot">ServerRoot</A>. This file sets the default list of
511 mappings from filename extensions to content types; changing this file is not
512 recommended. Use the <A HREF="#addtype">AddType</A> directive instead. The
513 file contains lines in the format of the arguments to an AddType command:
514 <BLOCKQUOTE><EM>MIME-type extension extension ...</EM></BLOCKQUOTE>
515 The extensions are lower-cased. Blank lines, and lines beginning with a hash
516 character (`#') are ignored.<P>
517
518 <!--#include virtual="footer.html" -->
519 </BODY>
520 </HTML>
521