1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4 <html xmlns="http://www.w3.org/1999/xhtml">
6 <meta name="generator" content="HTML Tidy, see www.w3.org" />
8 <title>PATH_INFO Changes in the CGI Environment</title>
10 <!-- Background white, links blue (unvisited), navy (visited), red (active) -->
12 <body bgcolor="#FFFFFF" text="#000000" link="#0000FF"
13 vlink="#000080" alink="#FF0000">
14 <!--#include virtual="header.html" -->
16 <h1 align="CENTER">PATH_INFO Changes in the CGI
20 <h2><a id="over" name="over">Overview</a></h2>
22 <p>As implemented in Apache 1.1.1 and earlier versions, the
23 method Apache used to create PATH_INFO in the CGI environment
24 was counterintuitive, and could result in crashes in certain
25 cases. In Apache 1.2 and beyond, this behavior has changed.
26 Although this results in some compatibility problems with
27 certain legacy CGI applications, the Apache 1.2 behavior is
28 still compatible with the CGI/1.1 specification, and CGI
29 scripts can be easily modified (<a href="#compat">see
32 <h2><a id="prob" name="prob">The Problem</a></h2>
34 <p>Apache 1.1.1 and earlier implemented the PATH_INFO and
35 SCRIPT_NAME environment variables by looking at the filename,
36 not the URL. While this resulted in the correct values in many
37 cases, when the filesystem path was overloaded to contain path
38 information, it could result in errant behavior. For example,
39 if the following appeared in a config file:</p>
41 Alias /cgi-ralph /usr/local/httpd/cgi-bin/user.cgi/ralph
44 <p>In this case, <code>user.cgi</code> is the CGI script, the
45 "/ralph" is information to be passed onto the CGI. If this
46 configuration was in place, and a request came for
47 "<code>/cgi-ralph/script/</code>", the code would set PATH_INFO
48 to "<code>/ralph/script</code>", and SCRIPT_NAME to
49 "<code>/cgi-</code>". Obviously, the latter is incorrect. In
50 certain cases, this could even cause the server to crash.</p>
52 <h2><a id="solution" name="solution">The Solution</a></h2>
54 <p>Apache 1.2 and later now determine SCRIPT_NAME and PATH_INFO
55 by looking directly at the URL, and determining how much of the
56 URL is client-modifiable, and setting PATH_INFO to it. To use
57 the above example, PATH_INFO would be set to
58 "<code>/script</code>", and SCRIPT_NAME to
59 "<code>/cgi-ralph</code>". This makes sense and results in no
60 server behavior problems. It also permits the script to be
62 "<code>http://$SERVER_NAME:$SERVER_PORT$SCRIPT_NAME$PATH_INFO</code>"
63 will always be an accessible URL that points to the current
64 script, something which was not necessarily true with previous
65 versions of Apache.</p>
67 <p>However, the "<code>/ralph</code>" information from the
68 <code>Alias</code> directive is lost. This is unfortunate, but
69 we feel that using the filesystem to pass along this sort of
70 information is not a recommended method, and a script making
71 use of it "deserves" not to work. Apache 1.2b3 and later,
72 however, do provide <a href="#compat">a workaround.</a></p>
74 <h2><a id="compat" name="compat">Compatibility with Previous
77 <p>It may be necessary for a script that was designed for
78 earlier versions of Apache or other servers to need the
79 information that the old PATH_INFO variable provided. For this
80 purpose, Apache 1.2 (1.2b3 and later) sets an additional
81 variable, FILEPATH_INFO. This environment variable contains the
82 value that PATH_INFO would have had with Apache 1.1.1.</p>
84 <p>A script that wishes to work with both Apache 1.2 and
85 earlier versions can simply test for the existence of
86 FILEPATH_INFO, and use it if available. Otherwise, it can use
87 PATH_INFO. For example, in Perl, one might use:</p>
89 $path_info = $ENV{'FILEPATH_INFO'} || $ENV{'PATH_INFO'};
92 <p>By doing this, a script can work with all servers supporting
93 the CGI/1.1 specification, including all versions of
95 <!--#include virtual="footer.html" -->