]> granicus.if.org Git - apache/blob - docs/manual/mod/mod_mime.html
Put in Paul's DefaultLanguage code. I don't recall seeing
[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 <A NAME="multipleext"><H2>Files with Multiple Extensions</H2></A>
52
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.
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="#sethandler">SetHandler</A>
96 <LI><A HREF="#typesconfig">TypesConfig</A>
97 </UL>
98 <HR>
99
100
101 <H2><A NAME="addencoding">AddEncoding</A></H2>
102 <!--%plaintext &lt;?INDEX {\tt AddEncoding} directive&gt; -->
103 <A
104  HREF="directive-dict.html#Syntax"
105  REL="Help"
106 ><STRONG>Syntax:</STRONG></A> AddEncoding <EM>MIME-enc extension extension...</EM><BR>
107 <A
108  HREF="directive-dict.html#Context"
109  REL="Help"
110 ><STRONG>Context:</STRONG></A> server config, virtual host, directory, .htaccess<BR>
111 <A
112  HREF="directive-dict.html#Override"
113  REL="Help"
114 ><STRONG>Override:</STRONG></A> FileInfo<BR>
115 <A
116  HREF="directive-dict.html#Status"
117  REL="Help"
118 ><STRONG>Status:</STRONG></A> Base<BR>
119 <A
120  HREF="directive-dict.html#Module"
121  REL="Help"
122 ><STRONG>Module:</STRONG></A> mod_mime<P>
123
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>.
129
130 Example:
131 <BLOCKQUOTE><CODE> AddEncoding x-gzip gz<BR> AddEncoding x-compress Z
132 </CODE></BLOCKQUOTE>
133
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>
137
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>.
149
150 <P>
151
152 <STRONG>See also</STRONG>: <A HREF="#multipleext">Files with
153 multiple extensions</A>
154
155 <P><HR>
156
157 <H2><A NAME="addhandler">AddHandler</A></H2>
158
159 <A
160  HREF="directive-dict.html#Syntax"
161  REL="Help"
162 ><STRONG>Syntax:</STRONG></A> AddHandler <EM>handler-name extension extension...</EM><BR>
163 <A
164  HREF="directive-dict.html#Context"
165  REL="Help"
166 ><STRONG>Context:</STRONG></A> server config, virtual host, directory, .htaccess<BR>
167 <A
168  HREF="directive-dict.html#Override"
169  REL="Help"
170 ><STRONG>Override:</STRONG></A> FileInfo<BR>
171 <A
172  HREF="directive-dict.html#Status"
173  REL="Help"
174 ><STRONG>Status:</STRONG></A> Base<BR>
175 <A
176  HREF="directive-dict.html#Module"
177  REL="Help"
178 ><STRONG>Module:</STRONG></A> mod_mime<BR>
179 <A
180  HREF="directive-dict.html#Compatibility"
181  REL="Help"
182 ><STRONG>Compatibility:</STRONG></A> AddHandler is only available in Apache
183 1.1 and later<P>
184
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>.
189
190 For example, to activate CGI scripts
191 with the file extension "<CODE>.cgi</CODE>", you might use:
192 <PRE>
193     AddHandler cgi-script cgi
194 </PRE>
195
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
198 CGI program.</P> 
199
200 <P>
201
202 <STRONG>See also</STRONG>: <A HREF="#multipleext">Files with
203 multiple extensions</A>
204
205 <HR>
206
207 <H2><A NAME="addlanguage">AddLanguage</A></H2>
208 <!--%plaintext &lt;?INDEX {\tt AddLanguage} directive&gt; -->
209 <A
210  HREF="directive-dict.html#Syntax"
211  REL="Help"
212 ><STRONG>Syntax:</STRONG></A> AddLanguage <EM>MIME-lang extension extension...</EM><BR>
213 <A
214  HREF="directive-dict.html#Context"
215  REL="Help"
216 ><STRONG>Context:</STRONG></A> server config, virtual host, directory, .htaccess<BR>
217 <A
218  HREF="directive-dict.html#Override"
219  REL="Help"
220 ><STRONG>Override:</STRONG></A> FileInfo<BR>
221 <A
222  HREF="directive-dict.html#Status"
223  REL="Help"
224 ><STRONG>Status:</STRONG></A> Base<BR>
225 <A
226  HREF="directive-dict.html#Module"
227  REL="Help"
228 ><STRONG>Module:</STRONG></A> mod_mime<P>
229
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>.
235
236 Example: <BLOCKQUOTE><CODE>
237 AddEncoding x-compress Z<BR> AddLanguage en .en<BR> AddLanguage fr
238 .fr<BR> </CODE></BLOCKQUOTE>
239
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>
247
248 <P>
249
250 <STRONG>See also</STRONG>: <A HREF="#multipleext">Files with
251 multiple extensions</A>
252
253 <HR>
254
255 <H2><A NAME="addtype">AddType</A></H2>
256 <!--%plaintext &lt;?INDEX {\tt AddType} directive&gt; -->
257 <A
258  HREF="directive-dict.html#Syntax"
259  REL="Help"
260 ><STRONG>Syntax:</STRONG></A> AddType <EM>MIME-type extension extension...</EM><BR>
261 <A
262  HREF="directive-dict.html#Context"
263  REL="Help"
264 ><STRONG>Context:</STRONG></A> server config, virtual host, directory, .htaccess<BR>
265 <A
266  HREF="directive-dict.html#Override"
267  REL="Help"
268 ><STRONG>Override:</STRONG></A> FileInfo<BR>
269 <A
270  HREF="directive-dict.html#Status"
271  REL="Help"
272 ><STRONG>Status:</STRONG></A> Base<BR>
273 <A
274  HREF="directive-dict.html#Module"
275  REL="Help"
276 ><STRONG>Module:</STRONG></A> mod_mime<P>
277
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).
285
286 Example:
287 <BLOCKQUOTE><CODE>
288 AddType image/gif GIF
289 </CODE></BLOCKQUOTE>
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>
294
295 <P>
296
297 <STRONG>See also</STRONG>: <A HREF="#multipleext">Files with
298 multiple extensions</A>
299
300 <HR>
301
302 <H2><A NAME="defaultlanguage">DefaultLanguage</A></H2>
303 <!--%plaintext &lt;?INDEX {\tt DefaultLanguage} directive&gt; -->
304 <A
305  HREF="directive-dict.html#Syntax"
306  REL="Help"
307 ><STRONG>Syntax:</STRONG></A> DefaultLanguage <EM>MIME-lang</EM><BR>
308 <A
309  HREF="directive-dict.html#Context"
310  REL="Help"
311 ><STRONG>Context:</STRONG></A> server config, virtual host, directory, .htaccess<BR>
312 <A
313  HREF="directive-dict.html#Override"
314  REL="Help"
315 ><STRONG>Override:</STRONG></A> FileInfo<BR>
316 <A
317  HREF="directive-dict.html#Status"
318  REL="Help"
319 ><STRONG>Status:</STRONG></A> Base<BR>
320 <A
321  HREF="directive-dict.html#Module"
322  REL="Help"
323 ><STRONG>Module:</STRONG></A> mod_mime<P>
324
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>&lt;Directory&gt;</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.
333
334 <P>
335
336 <STRONG>See also</STRONG>: <A HREF="#multipleext">Files with
337 multiple extensions</A>
338
339 <HR>
340
341 <H2><A NAME="forcetype">ForceType</A></H2>
342
343 <A
344  HREF="directive-dict.html#Syntax"
345  REL="Help"
346 ><STRONG>Syntax:</STRONG></A> ForceType <EM>media type</EM><BR>
347 <A
348  HREF="directive-dict.html#Context"
349  REL="Help"
350 ><STRONG>Context:</STRONG></A> directory, .htaccess<BR>
351 <A
352  HREF="directive-dict.html#Status"
353  REL="Help"
354 ><STRONG>Status:</STRONG></A> Base<BR>
355 <A
356  HREF="directive-dict.html#Module"
357  REL="Help"
358 ><STRONG>Module:</STRONG></A> mod_mime<BR>
359 <A
360  HREF="directive-dict.html#Compatibility"
361  REL="Help"
362 ><STRONG>Compatibility:</STRONG></A> ForceType is only available in Apache
363 1.1 and later.<P>
364
365 <P>When placed into an <CODE>.htaccess</CODE> file or a
366 <CODE>&lt;Directory&gt;</CODE> or <CODE>&lt;Location&gt;</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:
371 <PRE>
372     ForceType image/gif
373 </PRE>
374 <P>Note that this will override any filename extensions that might determine
375 the media type.</P><HR>
376
377 <H2><A NAME="sethandler">SetHandler</A></H2>
378
379 <A
380  HREF="directive-dict.html#Syntax"
381  REL="Help"
382 ><STRONG>Syntax:</STRONG></A> SetHandler <EM>handler-name</EM><BR>
383 <A
384  HREF="directive-dict.html#Context"
385  REL="Help"
386 ><STRONG>Context:</STRONG></A> directory, .htaccess<BR>
387 <A
388  HREF="directive-dict.html#Status"
389  REL="Help"
390 ><STRONG>Status:</STRONG></A> Base<BR>
391 <A
392  HREF="directive-dict.html#Module"
393  REL="Help"
394 ><STRONG>Module:</STRONG></A> mod_mime<BR>
395 <A
396  HREF="directive-dict.html#Compatibility"
397  REL="Help"
398 ><STRONG>Compatibility:</STRONG></A> SetHandler is only available in Apache
399 1.1 and later.<P>
400
401 <P>When placed into an <CODE>.htaccess</CODE> file or a
402 <CODE>&lt;Directory&gt;</CODE> or <CODE>&lt;Location&gt;</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:
409 <PRE>
410     SetHandler imap-file
411 </PRE>
412
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:
416 <PRE>
417     &lt;Location /status&gt;
418     SetHandler server-status
419     &lt;/Location&gt;
420 </PRE>
421 <HR>
422
423 <H2><A NAME="typesconfig">TypesConfig</A></H2>
424 <!--%plaintext &lt;?INDEX {\tt TypesConfig} directive&gt; -->
425 <A
426  HREF="directive-dict.html#Syntax"
427  REL="Help"
428 ><STRONG>Syntax:</STRONG></A> TypesConfig <EM>filename</EM><BR>
429 <A
430  HREF="directive-dict.html#Default"
431  REL="Help"
432 ><STRONG>Default:</STRONG></A> <CODE>TypesConfig conf/MIME.types</CODE><BR>
433 <A
434  HREF="directive-dict.html#Context"
435  REL="Help"
436 ><STRONG>Context:</STRONG></A> server config<BR>
437 <A
438  HREF="directive-dict.html#Status"
439  REL="Help"
440 ><STRONG>Status:</STRONG></A> Base<BR>
441 <A
442  HREF="directive-dict.html#Module"
443  REL="Help"
444 ><STRONG>Module:</STRONG></A> mod_mime<P>
445
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>
455
456 <!--#include virtual="footer.html" -->
457 </BODY>
458 </HTML>
459