cgi_path.xml revision acc36ab93565d2880447d535da6ca6e5feac7a70
beff4152e9f0fe90885458d1a1733b183a2a8816Christian Maeder<!DOCTYPE manualpage SYSTEM "/style/manualpage.dtd">
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder<?xml-stylesheet type="text/xsl" href="/style/manual.en.xsl"?>
98890889ffb2e8f6f722b00e265a211f13b5a861Corneliu-Claudiu Prodescu Copyright 2002-2004 Apache Software Foundation
3f69b6948966979163bdfe8331c38833d5d90ecdChristian Maeder Licensed under the Apache License, Version 2.0 (the "License");
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder you may not use this file except in compliance with the License.
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder You may obtain a copy of the License at
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder Unless required by applicable law or agreed to in writing, software
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder distributed under the License is distributed on an "AS IS" BASIS,
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder See the License for the specific language governing permissions and
0a26144c20fa9cdcd05011ca5019cbac8e4afae0cmaeder limitations under the License.
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder <title>PATH_INFO Changes in the CGI Environment</title>
bbba10ee00dcf6bcbc9f22473b1acd0983b10512notanartist <p>As implemented in Apache 1.1.1 and earlier versions, the
bbba10ee00dcf6bcbc9f22473b1acd0983b10512notanartist method Apache used to create PATH_INFO in the CGI environment
bbba10ee00dcf6bcbc9f22473b1acd0983b10512notanartist was counterintuitive, and could result in crashes in certain
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder cases. In Apache 1.2 and beyond, this behavior has changed.
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder Although this results in some compatibility problems with
ea5ccb1c6e89486a54e1f4bd95840147e96093edChristian Maeder certain legacy CGI applications, the Apache 1.2 behavior is
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder still compatible with the CGI/1.1 specification, and CGI
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder scripts can be easily modified (<a href="#compat">see
91e24fc45834b35f2a3830d72565640251149bf3Christian Maeder <section id="prob"><title>The Problem</title>
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder <p>Apache 1.1.1 and earlier implemented the PATH_INFO and
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder SCRIPT_NAME environment variables by looking at the filename,
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder not the URL. While this resulted in the correct values in many
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder cases, when the filesystem path was overloaded to contain path
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder information, it could result in errant behavior. For example,
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder if the following appeared in a config file:</p>
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder Alias /cgi-ralph /usr/local/httpd/cgi-bin/user.cgi/ralph
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder <p>In this case, <code>user.cgi</code> is the CGI script, the
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder "/ralph" is information to be passed onto the CGI. If this
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder configuration was in place, and a request came for
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder "<code>/cgi-ralph/script/</code>", the code would set PATH_INFO
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder to "<code>/ralph/script</code>", and SCRIPT_NAME to
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder "<code>/cgi-</code>". Obviously, the latter is incorrect. In
bbba6dd86153aacb0f662b182b128df0eb09fd54Christian Maeder certain cases, this could even cause the server to crash.</p>
4eb859461f8fd904f40f57261cf23e5c73cf8ecaChristian Maeder <section id="solution"><title>The Solution</title>
a31430de8b0632d29f42634d6395e982bf31b14dChristian Maeder <p>Apache 1.2 and later now determine SCRIPT_NAME and PATH_INFO
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder by looking directly at the URL, and determining how much of the
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder URL is client-modifiable, and setting PATH_INFO to it. To use
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder the above example, PATH_INFO would be set to
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder "<code>/cgi-ralph</code>". This makes sense and results in no
16b71dad8d398af412d66a4f4763f1ada5b03d23Christian Maeder server behavior problems. It also permits the script to be
f39b8dd9651dfcc38b06191cda23cacbfc298323Christian Maeder guaranteed that
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder "<code>http://$SERVER_NAME:$SERVER_PORT$SCRIPT_NAME$PATH_INFO</code>"
7f7460e7095628f3437b116ee78d3043d11f8febChristian Maeder will always be an accessible URL that points to the current
3a9d784341454573b50b32fa1b494e7418df3086Christian Maeder script, something which was not necessarily true with previous
dff1de7ad15d1582e25d636c3724dd202874897fChristian Maeder versions of Apache.</p>
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder <p>However, the "<code>/ralph</code>" information from the
9d6562465b41f17c7967d4e5678f34811d958cb2Christian Maeder <code>Alias</code> directive is lost. This is unfortunate, but
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder we feel that using the filesystem to pass along this sort of
502483734c83d0bf1eadcc94113d0362f8713784Christian Maeder information is not a recommended method, and a script making
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder use of it "deserves" not to work. Apache 1.2b3 and later,
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder however, do provide <a href="#compat">a workaround.</a></p>
96ae1a1d2197d0e0d5b80da2474b64c456feb1b0Christian Maeder <title>Compatibility with Previous Servers</title>
38c817b94e0a5b1ae94178b1075c187e07bcc5e1Christian Maeder <p>It may be necessary for a script that was designed for
38c817b94e0a5b1ae94178b1075c187e07bcc5e1Christian Maeder earlier versions of Apache or other servers to need the
38c817b94e0a5b1ae94178b1075c187e07bcc5e1Christian Maeder information that the old PATH_INFO variable provided. For this
38c817b94e0a5b1ae94178b1075c187e07bcc5e1Christian Maeder purpose, Apache 1.2 (1.2b3 and later) sets an additional
4eb859461f8fd904f40f57261cf23e5c73cf8ecaChristian Maeder variable, FILEPATH_INFO. This environment variable contains the
4eb859461f8fd904f40f57261cf23e5c73cf8ecaChristian Maeder value that PATH_INFO would have had with Apache 1.1.1.</p>
4eb859461f8fd904f40f57261cf23e5c73cf8ecaChristian Maeder <p>A script that wishes to work with both Apache 1.2 and
4eb859461f8fd904f40f57261cf23e5c73cf8ecaChristian Maeder earlier versions can simply test for the existence of
4eb859461f8fd904f40f57261cf23e5c73cf8ecaChristian Maeder FILEPATH_INFO, and use it if available. Otherwise, it can use
4eb859461f8fd904f40f57261cf23e5c73cf8ecaChristian Maeder PATH_INFO. For example, in Perl, one might use:</p>
2353f65833a3da763392f771223250cd50b8d873Christian Maeder $path_info = $ENV{'FILEPATH_INFO'} || $ENV{'PATH_INFO'};
dff1de7ad15d1582e25d636c3724dd202874897fChristian Maeder <p>By doing this, a script can work with all servers supporting
dff1de7ad15d1582e25d636c3724dd202874897fChristian Maeder the CGI/1.1 specification, including all versions of