AlpineWeb Home
Search: For:   ~ Advanced Search  
  Support Home     Documentation     Knowledgebase     Help Desk     Blog 
Support Home > VPS v1 > Webserver > Configuration > Sunday, October 12, 2008

Serving Documents Based on Language Preference


The Apache Web Server has the ability to look at the language preference specified by a browser client and return the content of different files depending on that preference. This ability, termed "language content negotiation", is a simple yet very powerful feature of the Apache server that is not often used.

There are essentially two approaches to content negotiation. The first uses a "variants" file (or a "var" file) which essentially lists document resources file by file and identifies them with a specific language. This may be convenient for small sites or if you only want to provide language typing for an entry page of a web site (which would then explicitly link to web content authored in different languages). The second approach uses file extensions (just like MIME types) to associate a file with a language.

Please find below a list of the steps necessary to configure the web services on your Virtual Server to perform language content negotiation by file extension. More information about configuring language content negotiation on a file by file basis can be found by reading the reference documents included at the bottom of this page.
  1. Add language type definitions to your web server configuration file

    Using whatever method you find convenient, edit the ~/www/conf/httpd.conf on your Virtual Private Server or the ~/www/conf/srm.conf file, if you VPS was configured before Dec. 8, 1998) and add language definitions using the AddLanguage directive. For example, add the following lines to your httpd.conf or srm.conf file:
    AddLanguage en .en
    AddLanguage es .es
    AddLanguage fr .fr
    AddLanguage de .de
    AddLanguage it .it
    AddLanguage jp .jp
    Basically, this will associate the file extensions, .en .es .fr .de .it .jp, with the corresponding language abbreviations, en es fr de it and jp. The abbreviations are pre-defined and can be located in any of the latest generations of browser clients. For example, in Netscape 4.x they are found in "Edit->Preferences->smalltextator->Language->Add(button)". In MSIE 4.x they are found in "View->Internet Options->General(tab)->Languages(button)->Add(button)".
  2. Add language priority definition to your web server configuration file

    Using whatever method you find convenient, edit the ~/www/conf/httpd.conf file on your VPS (or the ~/www/conf/srm.conf file, if you Virtual Server was configured before Dec. 8, 1998) and and add a language priority definition using the LanguagePriority directive. For example, add the following line to your httpd.conf or srm.conf file:
    LanguagePriority en es fr de


    The language priority directive allows you to give precedence to some languages in case of a "tie" during content negotiation or if the browser client does not specify a language priority (older browsers). Just list the languages in decreasing order of preference.
  3. Modify the Options definition for your htdocs area to include "MultiViews"

    Using whatever method you find convenient, edit the file access.conf (located in your ~/www/conf directory) and add the option "MultiViews" to the Options directive that is part of your htdocs Directory definition. For example, your Options line may look something like this:
    Options Indexes FollowSymLinks MultiViews
    The "MultiViews" option can also be added to the "Options" definition in .htaccess files.
That's it! Now you will need to author content and upload it to your Virtual Server using appropriate extensions. For example, you would create "index.html.en", "index.html.es", "index.html.fr", etc. instead of an "index.html". When the browser client requests "index.html", the server will analyze the language preference of the browser client and serve the appropriate "index.html.*" file seamlessly and transparently.

There is at least one snag. If the language preference the browser submits does match any of the type definitions on your server and documents you have authored. The server will return a 406 error (i.e. the resource was found, but could not be delivered because the type of the resource is incompatible with the acceptable types indicated by the accept or accept-encoding headers sent to the server by the client). So, for example, if a client will only accept Greek content (el) and nothing else, but you have only authored content in English, Spanish, and German, the client will receive a 406 error. It may be wise to capture the 406 errors with a custom ErrorDocument script.

References

Content Negotiation Explained (Apache Week Feature)
Content Negotiation (Apache.Org Documentation)

Technical Support
° Getting Started Guide
  FreeBSD
° VPS v1 Help
° VPS v2/3 Help
° MPS v2/3 Help
  DNS
° Domain Name Service
° Domain Registration
   
° Help Desk
° Knowledgebase
° Support Policies
° Disclaimer

° AlpineWeb Home
° Compare Hosting Plans
° Network Topology

° Rates & Fees
° Order Center




  Home | Site Map | Customer Backroom Copyright  ©  1997-2008  AlpineWeb Design