Content Negotiation

Content Negotiation is a HTTP technology for sending the “most accepted” content of a resource to the browser. It makes defining URIs much more simpler and error prone.

Content Negotiation is a common HTTP feature used for serving the “most accepted” content of a resource. Usually a web browsers request contains several Accept-* headers such as Accept-Language or Accept (accepted Content Types). These information tell the web server what kind of content the client (browser), and this means in most cases its user, prefers. Using the information a web server looks for a resource that fits the conditions best and servers it. As you can see, this technology makes localizations of your web sites very easy, but you can also provide special ASCII Art variants of your nice pictures for text browsers like lynx. Another aspect is that it helps you designing your URIs (in this context the W3C published Managing URIs): Assume your web site currently uses plain HTML files (*.html), but someday you decide using Python CGIs (*.py) reading your articles from a database. Instead of changing all hyperlinks on your site Content Negotiation makes sure that no links and especially bookmarks get broken.

As you can see in your address bar, the URI of this document seems to be /appendix/content-negotiation.shtml (relative to the web servers root directory), but indeed it is content-negotiation.shtml (relative to the current directory). Well, what if SF.net or even the Apache Team decide someday to use a new model of SSI with the (hypothetic) file extension xhtml-inc or I use PHP for extended dynamic content? This files name (including extension) will then be content-negotiation.xhtml-inc (or content-negotiation.php), but you will still request the resource /appendix/content-negotiation.shtml, your bookmark and search engines databses will keep valid. (Using the motto “Security by Obscurity” Content Negotiation also helps you keeping your real used server side technology secret since you can hardly guess if a resource is plain HTML, SSI, PHP or anything else.)

But the greatest advantage of Content Negotiation is that it helps you providing the “most acceptable” content for a resource. A good example for this are localizations: You may provide a certain document, e.g. this one, under a static URI, such as faq, but there is no such file on the web server; instead your english speaking visitors will really read a file named faq.shtml.en, except the US Amerians, that get faq.shtml.en-us, Germans will read faq.shtml.de and Frech receive faq.php.fr containing some dynamic content. I use this technology for presenting the screenshots: If viewing the nice pictures with a English browser, you see shots of the English localization, with a German user-agent there are German pictures. The Apache Documentation also mentiones this: Their maybe JPEG pictures for standard (graphical) web browser, but also ASCII Art images for text browser like lynx.

The most simple way activating Content Negotiation with your Apache web server is adding the following line to a Directory section of your /etc/httpd/httpd.conf or in a local .htaccess file:

Options +MultiViews

For the option of using so-called Type Maps refer to the Apache documentation.


Revision History

Revision 1.0
initial

Copyright © 2004 Robert Bienert – hosted at SourceForge.net Logo