"Switch" Documents

Using a Switch Document

A "switch" document is a special facility provided to web page owners at MV Communications.

The purpose of a switch document is to choose between multiple versions of a given page based on information about the client viewing the document. Criteria include the browser type, host from which they are browsing, MIME types they accept, and the time of day.

Comments, bugs, and suggestions should be posted to the mv.forum.web newsgroup or emailed to us.


A switch document at MV is a file with an extension of .sw (or any other document with a MIME type of script/switch). To use a switch document, simply create a file with the switch extension, compose it according to the guidelines below, and refer to it in a URL.

The switch document contains a list of files that might be served to the client, along with the criteria by which those files might be selected. Each line contains some information about when to choose a a particular file, plus the reference to the file to be served. Specifically, each line contains four space-separated items:

  1. What to check (browser, address, ip, accept, time, *)
  2. Pattern to look for
  3. File to serve
  4. MIME type to specify (optional)

    Note that any line that is blank or begins with a pound sign (#) is ignored.

    The first item on each line should be one of these words:

    browser
    The browser that the client is using. Example patterns would be like Mozilla/2* or Lynx*

    address
    The internet address (domain name) of the client, like *.mv.com

    ip
    The internet IP address of the client, like 199.*.*.*

    accept
    The list of MIME types that the agent supports. Suitable example patterns would be *image/pjpeg* or *image/png*

    time
    Time of day. This is a range of HH:MM times, and is in 24-hour format, like 08:00-17:00 for business hours, or 21:00-06:00 for when you're normally sleeping. You may omit the minutes, like 8-17

    *
    An asterisk means always match; this should be used last to indicate a default entry.

    The second item is the pattern to match against. Patterns must match the entire entity (above), not just a prefix or suffix of the entity. An asterisk can be used to represent a wildcard match. Thus, most entries will end with an asterisk, and some will start with one. You can put asterisks in the middle, like this Mozilla/3*X11* to indicate Netscape 3 on a Unix (X11) machine.

    The third item is the file name to provide. It must be in the same directory as the switch file, and may not have any slashes in the name. If the name starts with http: ftp: or news: then an HTTP redirect is issued to make the client go to that page.

    The fourth item is the MIME type to tell the client that the file it is serving is. If you do not specify one, it will use the suffix of the file to guess the type, but this only works for html, gif, and jpeg files.

    An example switch file is thus:

    Example uses of such a file would be thus:


    To use the switch for your default index.html file, you can add this line to .htaccess to change the name of the default index file (the one the server uses when the client just asks for a directory):


    Note: Consider, even if you use this facility to automatically send different documents based on the browser type, that you still give the requestor a way to make this choice explicitly.