cgi_path.html revision 57d0156f7bbd9ea3a72342cf9912aba61d118702
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync <meta name="generator" content="HTML Tidy, see www.w3.org" />
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync <title>PATH_INFO Changes in the CGI Environment</title>
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync <!-- Background white, links blue (unvisited), navy (visited), red (active) -->
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync <body bgcolor="#FFFFFF" text="#000000" link="#0000FF"
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync <!--#include virtual="header.html" -->
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync Environment</h1>
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync <p>As implemented in Apache 1.1.1 and earlier versions, the
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync method Apache used to create PATH_INFO in the CGI environment
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync was counterintuitive, and could result in crashes in certain
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync cases. In Apache 1.2 and beyond, this behavior has changed.
032a52c5b2984e26e84c2961f8f7f98a3954c8f2vboxsync Although this results in some compatibility problems with
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync certain legacy CGI applications, the Apache 1.2 behavior is
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync still compatible with the CGI/1.1 specification, and CGI
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync scripts can be easily modified (<a href="#compat">see
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync <p>Apache 1.1.1 and earlier implemented the PATH_INFO and
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync SCRIPT_NAME environment variables by looking at the filename,
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync not the URL. While this resulted in the correct values in many
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync cases, when the filesystem path was overloaded to contain path
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync information, it could result in errant behavior. For example,
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync if the following appeared in a config file:</p>
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync Alias /cgi-ralph /usr/local/httpd/cgi-bin/user.cgi/ralph
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync <p>In this case, <code>user.cgi</code> is the CGI script, the
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync "/ralph" is information to be passed onto the CGI. If this
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync configuration was in place, and a request came for
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync "<code>/cgi-ralph/script/</code>", the code would set PATH_INFO
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync to "<code>/ralph/script</code>", and SCRIPT_NAME to
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync "<code>/cgi-</code>". Obviously, the latter is incorrect. In
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync certain cases, this could even cause the server to crash.</p>
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync <h2><a id="solution" name="solution">The Solution</a></h2>
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync <p>Apache 1.2 and later now determine SCRIPT_NAME and PATH_INFO
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync by looking directly at the URL, and determining how much of the
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync URL is client-modifiable, and setting PATH_INFO to it. To use
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync the above example, PATH_INFO would be set to
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync "<code>/cgi-ralph</code>". This makes sense and results in no
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync server behavior problems. It also permits the script to be
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync guaranteed that
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync "<code>http://$SERVER_NAME:$SERVER_PORT$SCRIPT_NAME$PATH_INFO</code>"
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync will always be an accessible URL that points to the current
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync script, something which was not necessarily true with previous
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync versions of Apache.</p>
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync <p>However, the "<code>/ralph</code>" information from the
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync <code>Alias</code> directive is lost. This is unfortunate, but
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync we feel that using the filesystem to pass along this sort of
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync information is not a recommended method, and a script making
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync use of it "deserves" not to work. Apache 1.2b3 and later,
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync however, do provide <a href="#compat">a workaround.</a></p>
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync <h2><a id="compat" name="compat">Compatibility with Previous
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync <p>It may be necessary for a script that was designed for
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync earlier versions of Apache or other servers to need the
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync information that the old PATH_INFO variable provided. For this
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync purpose, Apache 1.2 (1.2b3 and later) sets an additional
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync variable, FILEPATH_INFO. This environment variable contains the
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync value that PATH_INFO would have had with Apache 1.1.1.</p>
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync <p>A script that wishes to work with both Apache 1.2 and
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync earlier versions can simply test for the existence of
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync FILEPATH_INFO, and use it if available. Otherwise, it can use
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync PATH_INFO. For example, in Perl, one might use:</p>
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync $path_info = $ENV{'FILEPATH_INFO'} || $ENV{'PATH_INFO'};
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync <p>By doing this, a script can work with all servers supporting
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync the CGI/1.1 specification, including all versions of
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync Apache.</p>
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync <!--#include virtual="footer.html" -->