Sample configuration

The following extracts from an Apache httpd.conf file show one possible configuration of this module. This may not necessarily be the best configuration possible, and may not work for your site correctly, particularly if you have a large number of existing HTML (non XHTML) documents.

#
# Set up logging for xhtml module.
#
XhtmlNegLog /var/log/apache/mod_xhtml.log

(...)

#
# This should be changed to whatever you set DocumentRoot to.
#
<Directory /var/www/>
   (...)
  XhtmlNegActive on
  XhtmlNegTypes .html application/xhtml+xml;charset=iso-8859-1 \
            application/xml;q=0.5 text/html;charset=iso-8859-1;q=0.8 \
            text/xml;charset=iso-8859-1;q=0.2
  XhtmlNegTypes .htm application/xhtml+xml;charset=iso-8859-1 \
            text/html;charset=iso-8859-1;q=0.8 application/xml;q=0.5 \
				text/xml;charset=iso-8859-1;q=0.2
  XhtmlNegStarsIgnore 2

  (...)
</Directory>

Note that the line breaks signified by the \ at the end of each line are not present in the actual Apache config file, but are there for formatting reasons only.

Decoding this, it translates as follows:

#
# Set up logging for xhtml module.
#
XhtmlNegLog /var/log/apache/mod_xhtml.log

Set up a log file at /var/log/apache/mod_xhtml.log, and write messages to that log file

  XhtmlNegActive on

Turn on XHTML negotiation for this directory and subdirectories.

  XhtmlNegTypes .html application/xhtml+xml;charset=iso-8859-1 \
            application/xml;q=0.5 text/html;charset=iso-8859-1;q=0.8 \
            text/xml;charset=iso-8859-1;q=0.2

For filenames ending in ".html" do the following negotiation:

  XhtmlNegTypes .htm application/xhtml+xml;charset=iso-8859-1 \
            text/html;charset=iso-8859-1;q=0.8 application/xml;q=0.5 \
				text/xml;charset=iso-8859-1;q=0.2

This is very similar to the previous line, but with ".htm" file extensions instead. Note that in this example the preferences don't depend on the order they're specified on the configuration line, because it's the "q" parameter that determines the order of the preference.**

  XhtmlNegStarsIgnore 2

Accept headers of "*/*" are ignored when performing content negotiation. This gets around Internet Explorer's bad habit of sending "*/*" to match any content type, including text/html, which isn't otherwise mentioned in its Accept header.

Note:

If you're wondering where the default character set of iso-8859-1 came from in the example, this is due to RFC 2616, which explains that in the absense of any other character set, iso-8859-1 should be assumed. However, this is overridden by RFC 3023 in the case of "text/xml" and "text/xml-external-parsed-entity", where us-ascii is assumed instead.

Having said that, the easiest way to set a default character set is to use the AddDefaultCharset directive, which is handled by the Apache core. This will apply the specified character set to all types not specifically overridden. This is a lot easier to set up than having to specify charset parameters for each possible content type.

Note 2:

If a "q" parameter is not specified, a value of 1.0 is assumed. If two "q" parameters are the same, the first one in the configuration file is preferred over the second.


Back home.