]> granicus.if.org Git - apache/blob - docs/manual/mod/mod_mime.html
Be more careful when documenting the way that extensions are mapped to
[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="#forcetype">ForceType</A>
94 <LI><A HREF="#sethandler">SetHandler</A>
95 <LI><A HREF="#typesconfig">TypesConfig</A>
96 </UL>
97 <HR>
98
99
100 <H2><A NAME="addencoding">AddEncoding</A></H2>
101 <!--%plaintext &lt;?INDEX {\tt AddEncoding} directive&gt; -->
102 <A
103  HREF="directive-dict.html#Syntax"
104  REL="Help"
105 ><STRONG>Syntax:</STRONG></A> AddEncoding <EM>MIME-enc extension extension...</EM><BR>
106 <A
107  HREF="directive-dict.html#Context"
108  REL="Help"
109 ><STRONG>Context:</STRONG></A> server config, virtual host, directory, .htaccess<BR>
110 <A
111  HREF="directive-dict.html#Override"
112  REL="Help"
113 ><STRONG>Override:</STRONG></A> FileInfo<BR>
114 <A
115  HREF="directive-dict.html#Status"
116  REL="Help"
117 ><STRONG>Status:</STRONG></A> Base<BR>
118 <A
119  HREF="directive-dict.html#Module"
120  REL="Help"
121 ><STRONG>Module:</STRONG></A> mod_mime<P>
122
123 The AddEncoding directive maps the given filename extensions to the
124 specified encoding type. <EM>Mime-enc</EM> is the mime encoding to use
125 for documents containing the <EM>extension</EM>. This mapping is added
126 to any already in force, overriding any mappings that already exist
127 for the same <EM>extension</EM>.
128
129 Example:
130 <BLOCKQUOTE><CODE> AddEncoding x-gzip gz<BR> AddEncoding x-compress Z
131 </CODE></BLOCKQUOTE>
132
133 This will cause filenames containing the .gz extension to be marked as
134 encoded using the x-gzip encoding, and filenames containing the .Z
135 extension to be marked as encoded with x-compress.<P>
136
137 Old clients expect <CODE>x-gzip</CODE> and <CODE>x-compress</CODE>,
138 however the standard dictates that they're equivalent to <CODE>gzip</CODE>
139 and <CODE>compress</CODE> respectively.  Apache does content encoding
140 comparisons by ignoring any leading <CODE>x-</CODE>.  When responding
141 with an encoding Apache will use whatever form (<EM>i.e.</EM>, <CODE>x-foo</CODE>
142 or <CODE>foo</CODE>) the client requested.  If the client didn't
143 specifically request a particular form Apache will use the form given by
144 the <CODE>AddEncoding</CODE> directive.  To make this long story short,
145 you should always use <CODE>x-gzip</CODE> and <CODE>x-compress</CODE>
146 for these two specific encodings.  More recent encodings, such as
147 <CODE>deflate</CODE> should be specified without the <CODE>x-</CODE>.
148
149 <P>
150
151 <STRONG>See also</STRONG>: <A HREF="#multipleext">Files with
152 multiple extensions</A>
153
154 <P><HR>
155
156 <H2><A NAME="addhandler">AddHandler</A></H2>
157
158 <A
159  HREF="directive-dict.html#Syntax"
160  REL="Help"
161 ><STRONG>Syntax:</STRONG></A> AddHandler <EM>handler-name extension extension...</EM><BR>
162 <A
163  HREF="directive-dict.html#Context"
164  REL="Help"
165 ><STRONG>Context:</STRONG></A> server config, virtual host, directory, .htaccess<BR>
166 <A
167  HREF="directive-dict.html#Override"
168  REL="Help"
169 ><STRONG>Override:</STRONG></A> FileInfo<BR>
170 <A
171  HREF="directive-dict.html#Status"
172  REL="Help"
173 ><STRONG>Status:</STRONG></A> Base<BR>
174 <A
175  HREF="directive-dict.html#Module"
176  REL="Help"
177 ><STRONG>Module:</STRONG></A> mod_mime<BR>
178 <A
179  HREF="directive-dict.html#Compatibility"
180  REL="Help"
181 ><STRONG>Compatibility:</STRONG></A> AddHandler is only available in Apache
182 1.1 and later<P>
183
184 <P>AddHandler maps the filename extensions <EM>extension</EM> to the
185 <A HREF="../handler.html">handler</A> <EM>handler-name</EM>.  This
186 mapping is added to any already in force, overriding any mappings that
187 already exist for the same <EM>extension</EM>.
188
189 For example, to activate CGI scripts
190 with the file extension "<CODE>.cgi</CODE>", you might use:
191 <PRE>
192     AddHandler cgi-script cgi
193 </PRE>
194
195 <P>Once that has been put into your srm.conf or httpd.conf file, any
196 file containing the "<CODE>.cgi</CODE>" extension will be treated as a
197 CGI program.</P> 
198
199 <P>
200
201 <STRONG>See also</STRONG>: <A HREF="#multipleext">Files with
202 multiple extensions</A>
203
204 <HR>
205
206 <H2><A NAME="addlanguage">AddLanguage</A></H2>
207 <!--%plaintext &lt;?INDEX {\tt AddLanguage} directive&gt; -->
208 <A
209  HREF="directive-dict.html#Syntax"
210  REL="Help"
211 ><STRONG>Syntax:</STRONG></A> AddLanguage <EM>MIME-lang extension extension...</EM><BR>
212 <A
213  HREF="directive-dict.html#Context"
214  REL="Help"
215 ><STRONG>Context:</STRONG></A> server config, virtual host, directory, .htaccess<BR>
216 <A
217  HREF="directive-dict.html#Override"
218  REL="Help"
219 ><STRONG>Override:</STRONG></A> FileInfo<BR>
220 <A
221  HREF="directive-dict.html#Status"
222  REL="Help"
223 ><STRONG>Status:</STRONG></A> Base<BR>
224 <A
225  HREF="directive-dict.html#Module"
226  REL="Help"
227 ><STRONG>Module:</STRONG></A> mod_mime<P>
228
229 The AddLanguage directive maps the given filename extensions to the
230 specified content language. <EM>Mime-lang</EM> is the mime language of
231 filenames containing <EM>extension</EM>.  This mapping is added to any
232 already in force, overriding any mappings that already exist for the
233 same <EM>extension</EM>.
234
235 Example: <BLOCKQUOTE><CODE>
236 AddEncoding x-compress Z<BR> AddLanguage en .en<BR> AddLanguage fr
237 .fr<BR> </CODE></BLOCKQUOTE>
238
239 Then the document <CODE>xxxx.en.Z</CODE> will be treated as being a
240 compressed English document (as will the document
241 <CODE>xxxx.Z.en</CODE>). Although the content language is reported to
242 the client, the browser is unlikely to use this information. The
243 AddLanguage directive is more useful for content negotiation, where
244 the server returns one from several documents based on the client's
245 language preference.<P>
246
247 <P>
248
249 <STRONG>See also</STRONG>: <A HREF="#multipleext">Files with
250 multiple extensions</A>
251
252 <HR>
253
254 <H2><A NAME="addtype">AddType</A></H2>
255 <!--%plaintext &lt;?INDEX {\tt AddType} directive&gt; -->
256 <A
257  HREF="directive-dict.html#Syntax"
258  REL="Help"
259 ><STRONG>Syntax:</STRONG></A> AddType <EM>MIME-type extension extension...</EM><BR>
260 <A
261  HREF="directive-dict.html#Context"
262  REL="Help"
263 ><STRONG>Context:</STRONG></A> server config, virtual host, directory, .htaccess<BR>
264 <A
265  HREF="directive-dict.html#Override"
266  REL="Help"
267 ><STRONG>Override:</STRONG></A> FileInfo<BR>
268 <A
269  HREF="directive-dict.html#Status"
270  REL="Help"
271 ><STRONG>Status:</STRONG></A> Base<BR>
272 <A
273  HREF="directive-dict.html#Module"
274  REL="Help"
275 ><STRONG>Module:</STRONG></A> mod_mime<P>
276
277 The AddType directive maps the given filename extensions onto the
278 specified content type. <EM>Mime-enc</EM> is the mime type to use for
279 filenames containing <EM>extension</EM>.  This mapping is added to any
280 already in force, overriding any mappings that already exist for the
281 same <EM>extension</EM>. This directive can be used to add mappings
282 not listed in the mime types file (see the <CODE><A
283 HREF="#typesconfig">TypesConfig</A></CODE> directive).
284
285 Example:
286 <BLOCKQUOTE><CODE>
287 AddType image/gif GIF
288 </CODE></BLOCKQUOTE>
289 It is recommended that new mime types be added using the AddType directive
290 rather than changing the <A HREF="#typesconfig">TypesConfig</A> file.<P>
291 Note that, unlike the NCSA httpd, this directive cannot be used to set the
292 type of particular files.<P>
293
294 <P>
295
296 <STRONG>See also</STRONG>: <A HREF="#multipleext">Files with
297 multiple extensions</A>
298
299 <HR>
300
301 <H2><A NAME="forcetype">ForceType</A></H2>
302
303 <A
304  HREF="directive-dict.html#Syntax"
305  REL="Help"
306 ><STRONG>Syntax:</STRONG></A> ForceType <EM>media type</EM><BR>
307 <A
308  HREF="directive-dict.html#Context"
309  REL="Help"
310 ><STRONG>Context:</STRONG></A> directory, .htaccess<BR>
311 <A
312  HREF="directive-dict.html#Status"
313  REL="Help"
314 ><STRONG>Status:</STRONG></A> Base<BR>
315 <A
316  HREF="directive-dict.html#Module"
317  REL="Help"
318 ><STRONG>Module:</STRONG></A> mod_mime<BR>
319 <A
320  HREF="directive-dict.html#Compatibility"
321  REL="Help"
322 ><STRONG>Compatibility:</STRONG></A> ForceType is only available in Apache
323 1.1 and later.<P>
324
325 <P>When placed into an <CODE>.htaccess</CODE> file or a
326 <CODE>&lt;Directory&gt;</CODE> or <CODE>&lt;Location&gt;</CODE> section,
327 this directive forces all matching files to be served
328 as the content type given by <EM>media type</EM>. For example, if you
329 had a directory full of GIF files, but did not want to label them all with
330 ".gif", you might want to use:
331 <PRE>
332     ForceType image/gif
333 </PRE>
334 <P>Note that this will override any filename extensions that might determine
335 the media type.</P><HR>
336
337 <H2><A NAME="sethandler">SetHandler</A></H2>
338
339 <A
340  HREF="directive-dict.html#Syntax"
341  REL="Help"
342 ><STRONG>Syntax:</STRONG></A> SetHandler <EM>handler-name</EM><BR>
343 <A
344  HREF="directive-dict.html#Context"
345  REL="Help"
346 ><STRONG>Context:</STRONG></A> directory, .htaccess<BR>
347 <A
348  HREF="directive-dict.html#Status"
349  REL="Help"
350 ><STRONG>Status:</STRONG></A> Base<BR>
351 <A
352  HREF="directive-dict.html#Module"
353  REL="Help"
354 ><STRONG>Module:</STRONG></A> mod_mime<BR>
355 <A
356  HREF="directive-dict.html#Compatibility"
357  REL="Help"
358 ><STRONG>Compatibility:</STRONG></A> SetHandler is only available in Apache
359 1.1 and later.<P>
360
361 <P>When placed into an <CODE>.htaccess</CODE> file or a
362 <CODE>&lt;Directory&gt;</CODE> or <CODE>&lt;Location&gt;</CODE> section,
363 this directive forces all matching files to be parsed through the
364 <A HREF="../handler.html">handler</A>
365 given by <EM>handler-name</EM>. For example, if you had a
366 directory you wanted to be parsed entirely as imagemap rule files,
367 regardless of extension, you might put the following into an
368 <CODE>.htaccess</CODE> file in that directory:
369 <PRE>
370     SetHandler imap-file
371 </PRE>
372
373 <P>Another example: if you wanted to have the server display a status
374 report whenever a URL of <CODE>http://servername/status</CODE> was
375 called, you might put the following into access.conf:
376 <PRE>
377     &lt;Location /status&gt;
378     SetHandler server-status
379     &lt;/Location&gt;
380 </PRE>
381 <HR>
382
383 <H2><A NAME="typesconfig">TypesConfig</A></H2>
384 <!--%plaintext &lt;?INDEX {\tt TypesConfig} directive&gt; -->
385 <A
386  HREF="directive-dict.html#Syntax"
387  REL="Help"
388 ><STRONG>Syntax:</STRONG></A> TypesConfig <EM>filename</EM><BR>
389 <A
390  HREF="directive-dict.html#Default"
391  REL="Help"
392 ><STRONG>Default:</STRONG></A> <CODE>TypesConfig conf/mime.types</CODE><BR>
393 <A
394  HREF="directive-dict.html#Context"
395  REL="Help"
396 ><STRONG>Context:</STRONG></A> server config<BR>
397 <A
398  HREF="directive-dict.html#Status"
399  REL="Help"
400 ><STRONG>Status:</STRONG></A> Base<BR>
401 <A
402  HREF="directive-dict.html#Module"
403  REL="Help"
404 ><STRONG>Module:</STRONG></A> mod_mime<P>
405
406 The TypesConfig directive sets the location of the mime types configuration
407 file. <EM>Filename</EM> is relative to the
408 <A HREF="core.html#serverroot">ServerRoot</A>. This file sets the default list of
409 mappings from filename extensions to content types; changing this file is not
410 recommended. Use the <A HREF="#addtype">AddType</A> directive instead. The
411 file contains lines in the format of the arguments to an AddType command:
412 <BLOCKQUOTE><EM>MIME-type extension extension ...</EM></BLOCKQUOTE>
413 The extensions are lower-cased. Blank lines, and lines beginning with a hash
414 character (`#') are ignored.<P>
415
416 <!--#include virtual="footer.html" -->
417 </BODY>
418 </HTML>
419