]> granicus.if.org Git - apache/blob - docs/manual/mod/mod_mime.html
Update the list of directives for BrowserMatch*'s new location,
[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 (e.g. a particular directory) onto a particular
43 mime type or handler.
44
45 <P>
46
47 Files can have more than one extension, and the order of the
48 extensions is normally irrelevant. For example, if the file
49 <CODE>welcome.html.fr</CODE> maps onto content type text/html and
50 language French then the file <CODE>welcome.fr.html</CODE> will map
51 onto exactly the same information. The only exception to this is if an
52 extension is given which Apache does not know how to handle. In this
53 case it will "forget" about any information it obtained from
54 extensions to the left of the unknown extension. So, for example, if
55 the extensions fr and html are mapped to the appropriate language and
56 type but extension xxx is not assigned to anything, then the file
57 <CODE>welcome.fr.xxx.html</CODE> will be associated with content-type
58 text/html but <i>no</i> language.
59
60 <P>
61
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.
65
66 <P>
67
68 Please note that changing a file's type or encoding does not change
69 the value of the <code>Last-Modified</code> header. Previously cached
70 copies may still be used by a client or proxy.
71
72 <P>
73
74 <h2> Directives</h2>
75 <ul>
76 <li><A HREF="#addencoding">AddEncoding</A>
77 <li><A HREF="#addhandler">AddHandler</A>
78 <li><A HREF="#addlanguage">AddLanguage</A>
79 <li><A HREF="#addtype">AddType</A>
80 <li><A HREF="#forcetype">ForceType</A>
81 <li><A HREF="#sethandler">SetHandler</A>
82 <li><A HREF="#typesconfig">TypesConfig</A>
83 </ul>
84 <hr>
85
86
87 <h2><A name="addencoding">AddEncoding</A></h2>
88 <!--%plaintext &lt;?INDEX {\tt AddEncoding} directive&gt; -->
89 <strong>Syntax:</strong> AddEncoding <em>mime-enc extension extension...</em><br>
90 <Strong>Context:</strong> server config, virtual host, directory, .htaccess<br>
91 <Strong>Override:</strong> FileInfo<br>
92 <strong>Status:</strong> Base<br>
93 <strong>Module:</strong> mod_mime<p>
94
95 The AddEncoding directive adds to the list of filename extensions which
96 filenames may end in for the specified encoding type. <em>Mime-enc</em>
97 is the mime encoding to use for documents ending in <em>extension</em>.
98 Example:
99 <blockquote><code>
100 AddEncoding x-gzip gz<br>
101 AddEncoding x-compress Z
102 </code></blockquote>
103
104 This will cause files ending in .gz to be marked as encoded using the x-gzip
105 encoding, and .Z files to be marked as encoded with x-compress.<p><hr>
106
107 <h2><a name="addhandler">AddHandler</a></h2>
108
109 <strong>Syntax:</strong> AddHandler <em>handler-name extension extension...</em><br>
110 <strong>Context:</strong> server config, virtual host, directory, .htaccess<br>
111 <strong>Status:</strong> Base<br>
112 <strong>Module:</strong> mod_mime<br>
113 <strong>Compatibility:</strong> AddHandler is only available in Apache
114 1.1 and later<p>
115
116 <p>AddHandler maps the filename extensions <em>extension</em> to the
117 <a href="../handler.html">handler</a>
118 <em>handler-name</em>. For example, to activate CGI scripts
119 with the file extension "<code>.cgi</code>", you might use:
120 <pre>
121     AddHandler cgi-script cgi
122 </pre>
123
124 <p>Once that has been put into your srm.conf or httpd.conf file, any
125 file ending with "<code>.cgi</code>" will be treated as a CGI
126 program.</p>
127 <HR>
128
129 <h2><A name="addlanguage">AddLanguage</A></h2>
130 <!--%plaintext &lt;?INDEX {\tt AddLanguage} directive&gt; -->
131 <strong>Syntax:</strong> AddLanguage <em>mime-lang extension extension...</em><br>
132 <Strong>Context:</strong> server config, virtual host, directory, .htaccess<br>
133 <Strong>Override:</strong> FileInfo<br>
134 <strong>Status:</strong> Base<br>
135 <strong>Module:</strong> mod_mime<p>
136
137 The AddLanguage directive adds to the list of filename extensions which
138 filenames may end in for the specified content language. <em>Mime-lang</em>
139 is the mime language of files with names ending <em>extension</em>,
140 after any content encoding extensions have been removed. Example:
141 <blockquote><code>
142 AddEncoding x-compress Z<br>
143 AddLanguage en .en<br>
144 AddLanguage fr .fr<br>
145 </code></blockquote>
146
147 Then the document <code>xxxx.en.Z</code> will be treated as being a compressed
148 English document. Although the content language is reported to the client,
149 the browser is unlikely to use this information. The AddLanguage directive
150 is more useful for content negotiation, where the server returns one
151 from several documents based on the client's language preference.<p><hr>
152
153 <h2><A name="addtype">AddType</A></h2>
154 <!--%plaintext &lt;?INDEX {\tt AddType} directive&gt; -->
155 <strong>Syntax:</strong> AddType <em>mime-type extension extension...</em><br>
156 <Strong>Context:</strong> server config, virtual host, directory, .htaccess<br>
157 <Strong>Override:</strong> FileInfo<br>
158 <strong>Status:</strong> Base<br>
159 <strong>Module:</strong> mod_mime<p>
160
161 The AddType directive adds to the list of filename extensions which
162 filenames may end in for the specified content type. <em>Mime-enc</em>
163 is the mime type to use for documents ending in <em>extension</em>.
164 after content-encoding and language extensions have been removed. Example:
165 <blockquote><code>
166 AddType image/gif GIF
167 </code></blockquote>
168 It is recommended that new mime types be added using the AddType directive
169 rather than changing the <A HREF="#typesconfig">TypesConfig</A> file.<p>
170 Note that, unlike the NCSA httpd, this directive cannot be used to set the
171 type of particular files.<p><hr>
172
173 <h2><a name="forcetype">ForceType</a></h2>
174
175 <strong>Syntax:</strong> ForceType <em>media type</em><br>
176 <strong>Context:</strong> directory, .htaccess<br>
177 <strong>Status:</strong> Base<br>
178 <strong>Module:</strong> mod_mime<br>
179 <strong>Compatibility:</strong> ForceType is only available in Apache
180 1.1 and later.<p>
181
182 <p>When placed into an <code>.htaccess</code> file or a
183 <code>&lt;Directory&gt;</code> or <code>&lt;Location&gt;</code> section,
184 this directive forces all matching files to be served
185 as the content type given by <em>media type</em>. For example, if you
186 had a directory full of GIF files, but did not want to label them all with
187 ".gif", you might want to use:
188 <pre>
189     ForceType image/gif
190 </pre>
191 <p>Note that this will override any filename extensions that might
192 media type.</p>
193
194 <h2><a name="sethandler">SetHandler</a></h2>
195
196 <strong>Syntax:</strong> SetHandler <em>handler-name</em><br>
197 <strong>Context:</strong> directory, .htaccess<br>
198 <strong>Status:</strong> Base<br>
199 <strong>Module:</strong> mod_mime<br>
200 <strong>Compatibility:</strong> SetHandler is only available in Apache
201 1.1 and later.<p>
202
203 <p>When placed into an <code>.htaccess</code> file or a
204 <code>&lt;Directory&gt;</code> or <code>&lt;Location&gt;</code> section,
205 this directive forces all matching files to be parsed through the
206 <a href="../handler.html">handler</a>
207 given by <em>handler-name</em>. For example, if you had a
208 directory you wanted to be parsed entirely as imagemap rule files,
209 regardless of extension, you might put the following into an
210 <code>.htaccess</code> file in that directory:
211 <pre>
212     SetHandler imap-file
213 </pre>
214
215 <p>Another example: if you wanted to have the server display a status
216 report whenever a URL of <code>http://servername/status</code> was
217 called, you might put the following into access.conf:
218 <pre>
219     &lt;Location /status&gt;
220     SetHandler server-status
221     &lt;/Location&gt;
222 </pre>
223 <HR>
224
225 <h2><A name="typesconfig">TypesConfig</A></h2>
226 <!--%plaintext &lt;?INDEX {\tt TypesConfig} directive&gt; -->
227 <strong>Syntax:</strong> TypesConfig <em>filename</em><br>
228 <strong>Default:</strong> <code>TypesConfig conf/mime.types</code><br>
229 <Strong>Context:</strong> server config<br>
230 <strong>Status:</strong> Base<br>
231 <strong>Module:</strong> mod_mime<p>
232
233 The TypesConfig directive sets the location of the mime types configuration
234 file. <em>Filename</em> is relative to the
235 <A HREF="core.html#serverroot">ServerRoot</A>. This file sets the default list of
236 mappings from filename extensions to content types; changing this file is not
237 recommended. Use the <A HREF="#addtype">AddType</A> directive instead. The
238 file contains lines in the format of the arguments to an AddType command:
239 <blockquote><em>mime-type extension extension ...</em></blockquote>
240 The extensions are lower-cased. Blank lines, and lines beginning with a hash
241 character (`#') are ignored.<p>
242
243 <!--#include virtual="footer.html" -->
244 </BODY>
245 </HTML>
246