start page | rating of books | rating of authors | reviews | copyrights

Book HomeApache: The Definitive GuideSearch this book

Chapter 6. MIME, Content and Language Negotiation

Contents:

MIME Types
Content Negotiation
Language Negotiation
Type Maps
Browsers and HTTP/1.1

Apache has the ability to tune its returns to the abilities of the client -- and even to improve the client's efforts. Currently, this affects:

6.1. MIME Types

MIME stands for Multimedia Internet Mail Extensions. The code used here is in mod_mime.c and is compiled in by default. It allows Apache to determine the type of a file from its extension. The list of MIME types that Apache already knows about is distributed in the file ..conf/mime.types or can be found at http://www.isi.edu/in-notes/iana/assignments/media-types/media-types. You can edit it to include extra types, or you can use the directives discussed in this chapter. The default location for the file is .../<site>/conf, but it may be more convenient to keep it elsewhere, in which case you would use the directive TypesConfig.

Changing the encoding of a file with one of these directives does not change the value of the Last-Modified header, so cached copies can be used. Files can have more than one extension, and their order normally doesn't matter. If the extension .itl maps onto Italian and .html maps onto HTML, then the files text.itl.html and text.html.itl will be treated alike. However, any unrecognized extension, say .xyz, wipes out all extensions to its left. Hence text.itl.xyz.html will be treated as HTML but not as Italian.

6.1.1. TypesConfig

TypesConfig filename 
Default: conf/mime.types
Server config

This directive sets the path and filename to find the mime.types file if it isn't in the default position.

6.1.2. AddType

AddType mime-type extension extension
Anywhere

This adds extensions to correspond to a content type. It may not be obvious how AddType differs from AddEncoding: a content type is "what it is" and an encoding is "how it gets there." HTML and GIF are content types; base 64 and ZIP are encodings.

Long ago, a process called "magic MIME types" was used to fiddle extra capability into Apache by using AddType. AddType should now only be used for genuine MIME types.

6.1.3. DefaultType

DefaultType mime-type
Anywhere

The server must inform the client of the content type of the document, so in the event of an unknown type it uses whatever is specified by the DefaultType directive. For example:

DefaultType image/gif

would be appropriate for a directory that contained many GIF images with file-names missing the .gif extension.

6.1.4. AddEncoding

AddEncoding mime-enc extension extension
Anywhere

This directive adds new types of encoding to the list. Hence:

AddEncoding x-gzip zip

will cause Apache to send x-gzip as the encoding for files with the extension .zip so that a file stuff.zip will automatically be unzipped as it is served.[50] For compatibility with older browsers, the prefix x- is specially handled, so that x-gzip is functionally the same as gzip. This is because the browser can say what it is prepared to handle with an Accept-Encoding header. If it says gzip, then Apache will send gzip, even if you've set x-gzip; similarly, if it says x-gzip, then so will Apache. But if the browser says nothing, Apache will say whatever you set, so you'd better set the old form (x-gzip) since the browser may also be old.

[50]Note that browser support for this useful facility is patchy at best, so, as the saying goes, YMMV (your mileage may vary).

6.1.5. ForceType

ForceType media-type
Directory, .htaccess

Given a directory full of files of a particular type, ForceType will cause them to be sent as media-type. For instance, you might have a collection of .gif files in the directory .../gifdir, but you don't want them to have that extension. You would include something like this in your Config file:

<Directory <path>/gifdir>
ForceType image/gif
</Directory>


Library Navigation Links

Copyright © 2001 O'Reilly & Associates. All rights reserved.