• Aucun résultat trouvé

mod_mime

Dans le document Apache Server2 Apache Server2 (Page 155-159)

mod_mime_magic Enables Apache to determine MIME type by using magic numbers (bytes pattern).

mod_negotiation Enables Apache to perform content negotiation to send out the best type of content that the client can accept.

mod_mime

The mod_mimemodule is compiled in Apache by default. It provides clients with meta information about documents. It also enables you to define a handler for a document to determine how the document is processed by Apache.

AddCharset

The AddCharsetdirective maps one or more file extensions to a MIME character set. This allows you to associate a character set to one or more file extensions.

Syntax: AddCharset charset file_extension [file_extension ...]

Context:Server config, virtual host, directory, per-directory configuration (.htaccess)

Override:FileInfo

The following example causes a file called filename.utf8to be mapped as a char-acter set called UTF-8.

AddCharset UTF-8 .utf8

AddEncoding

The AddEncodingdirective maps one or more file extensions to a MIME-encoding scheme. In other words, this directive associates an encoding scheme to one or more file extensions.

Syntax:AddEncoding MIME file_extension [file_extension...]

Context:Server config, virtual host, directory, per-directory configuration (.htaccess)

Override:FileInfo

For example, the following directives cause a file called backup.gzto be mapped as an x-gzip–encoded file, and a file called tarball.tarto be mapped as an x-tar–encoded file.

AddEncoding x-gzip gz AddEncoding x-tar tar

AddHandler

The AddHandlerdirective defines a handler for one or more file extensions.

Whenever Apache encounters a file with a defined handler it allows the handler to process the file.

Syntax:AddHandler handler-name file-extension [file-extension ...]

Context:Server config, virtual host, directory, per-directory access control file (.htaccess)

In the following example: the directive specifies that all .cgifiles be processed by a handler called cgi-script.

AddHandler cgi-script .cgi

AddLanguage

The AddLanguagedirective maps a list of file extensions to a MIME language.

When Apache encounters a file with such extension it knows what language the file supports.

Syntax:AddLanguage MIME_language file_extension [file_extension] [...]

Context: Server config, virtual host, directory, per-directory access control file (.htaccess)

Override:FileInfo

The following example maps all files with extensions .enor .englishto be mapped as English-language files. This is useful in content negotiation, where the server can return a document based on the client’s language preference.

AddLanguage en .en .english

Or, in the following example, if the client prefers an English document, and both document.fr.htmland document.en.htmlare available, the server should return document.en.html.

AddLanguage en .en AddLanguage fr .fr

AddType

The AddTypedirective maps a list of file extensions to a MIME type so that when Apache encounters files with such extensions it knows what MIME type to use for them.

Syntax: AddType MIME file_extension [file_extension ...]

Context:Server config, virtual host, directory, per-directory access control file (.htaccess)

Override:FileInfo

For example, the following line associates the MIME type called text/htmlto htm, html, HTML, and HTMLextensions.

AddType text/html htm html HTM HTML

DefaultLanguage

The DefaultLanguagedirective sets the default language.

Syntax:DefaultLanguage MIME_language

Context:Server config, virtual host, directory, per-directory configuration (.htaccess)

Override:FileInfo

For example, in the following directive all the contents in the

/www/mysite/Japanesedirectory are mapped to the default language, Japanese:

<Directory /www/mysite/japanese>

DefaultLanguage .jp

</Directory>

ForceType

The ForceTypedirective forces a certain MIME type for all files in a directory. The directory can be specified by a <Directory>or <Location>container.

Syntax:ForceType MIME_type

Context: Directory, per-directory access control file (.htaccess)

For example, the following directive forces the text/htmlMIME-type for all files in the specified directory, regardless of their extensions:

<Directory /www/nitec/public/htdocs/files/with/no/extensions>

ForceType text/html

</Directory>

SetHandler

The SetHandlerdirective defines a handler for a directory or a URL location.The handler is then used to process all files in the directory.

Syntax: SetHandler handler_name

Context: Directory, per-directory access control file (.htaccess)

For example, the following directive forces all files in the /binlocation to be treated as CGI scripts, which are handled by the cgi-binhandler:

<Location /bin>

Options ExecCGI SetHandler cgi-bin

</Location>

RemoveHandler

The RemoveHandlerdirective undoes a handler for a directory or a URL location.

It is useful to limit SetHandler, which normally applies to all the files in a direc-tory. Using RemoveHandleryou can remove handlers for some files or even a subdirectory.

Syntax:RemoveHandler handler_name

Context:Directory, per-directory access control file (.htaccess)

For example, in the following directive, the handler my-handleris set to an .mjk extension outside the /www/mysite/htdocs/specialdirectory, so it automati-cally applies to this directory as well. However, because RemoveHandleris applied to this directory to undo the my-handlerassociation with .mjk, files with .mjk extensions in this directory are not handled with my-handler:

SetHandler my-handler .mjk

<Directory /www/mysite/htdocs/special>

RemoveHandler .mjk

</Location>

TypesConfig

The TypesConfigdirective specifies the default MIME configuration file. The default value should be fine for most Apache installations. If you want to add your own MIME types, use the AddTypedirective instead of modifying this file.

Syntax:TypesConfig filename

Default setting:TypesConfig conf/mime.types Context:Server config

If you need additional support for handling MIME-types, you may want to look at the mod_mime_magicmodule in the next section. For most Apache installations this is not necessary, so it is not discussed in this book.

Dans le document Apache Server2 Apache Server2 (Page 155-159)