GoDaddy Support

Apache Multiviews

Date Submitted: 5-17-2010 by MikeD

Not what you're looking for?
We want your feedback!

Topic: Web Hosting

Apache Multiviews is a powerful content negotiation mechanism that can return different files for a given URL according to the language and encoding settings of the client web browser.  It is commonly used to select the appropriate language and/or format based on the user’s preferences.

Here’s a typical example:  say you want to provide English, French, and Spanish languages on your web site.  Create a version of each page for each language, naming the files with the language code extension:

  • page.html.en
  • page.html.fr
  • page.html.es

Now, make a request for page.html from your browser.  Apache recognizes that the file page.html does not exist, so Multiviews content negotiation kicks in and attempts to find an alternative file to fulfill the request.  It sees the three language versions of page.html and selects the appropriate language based on the preferred language of the browser (communicated via Accept: headers as part of the request.)  Apache returns page.html.en to English browsers for the page.html request, and similarly for French and Spanish browsers.

If no language match can be found based on the available alternative files and the browser preferences, Apache reports a 406 Not Acceptable error with links to all the available languages for the request.  This way the final decision on what language to display can be directly chosen by the user.

The same applies for non-static content that’s generated by PHP, Perl, etc.  Just create the different language versions of the script for the same behavior.

Configuration

Apache Multiviews is already enabled by default for sites on Go Daddy hosting. (See below for information about disabling the default behavior.)

For all the technical details, see the official Apache documentation.

Drawbacks

One problem with using Apache Multiviews to automatically select appropriate content for a request is you lose control of explicitly selecting what gets returned to the browser. It can also sometimes be unclear how a particular file with multiple extensions will be handled.

Script files are of particular concern. Say you have an old version of a script.pl file that you copy to script.pl.bak for backup purposes. A request for script.pl.bak will still be interpreted by Apache as a Perl script, causing the old version of your code to be executed! One can imagine other instances where a script file may be executed unintentionally because of this behavior by Apache.

Disable Multiviews and Multiple File Extension Behavior

To disable Apache Multiviews and the handling of script files with multiple extensions, you can insert the following configuration in the .htaccess file.

Options -MultiViews

AddHandler None .php
AddHandler None .php5
AddHandler None .php4
AddHandler None .pl
AddHandler None .py
AddHandler None .py23
AddHandler None .rb
AddHandler None .cgi

<FilesMatch \.php$>
     SetHandler x-httpd-php5      # For PHP5
     ## SetHandler x-httpd-php    # For PHP4
</FilesMatch>

<FilesMatch \.php5$>
     SetHandler x-httpd-php5
</FilesMatch>

<FilesMatch \.php4$>
     SetHandler x-httpd-php
</FilesMatch>

<FilesMatch \.pl$>
     SetHandler x-httpd-perl
</FilesMatch>

<FilesMatch \.py$>
     SetHandler x-httpd-python
</FilesMatch>

<FilesMatch \.py23$>
     SetHandler x-httpd-python
</FilesMatch>

<FilesMatch \.rb$>
     SetHandler x-httpd-ruby
</FilesMatch>

<FilesMatch \.cgi$>
     SetHandler cgi-script
</FilesMatch>

Comments are closed.

NEED HELP? Call our award-winning support team 24/7 at (480) 505-8877
Submit

United States - English
Traffic Log Image