env.html revision 25acd9a5f9553e60226609c083dd0c62a80fa9ff
d73ae94e59c019f5cc3221ee0a0012d02091b40egc<!-- Background white, links blue (unvisited), navy (visited), red (active) -->
d73ae94e59c019f5cc3221ee0a0012d02091b40egc BGCOLOR="#FFFFFF"
d73ae94e59c019f5cc3221ee0a0012d02091b40egc TEXT="#000000"
d73ae94e59c019f5cc3221ee0a0012d02091b40egc LINK="#0000FF"
d73ae94e59c019f5cc3221ee0a0012d02091b40egc VLINK="#000080"
d73ae94e59c019f5cc3221ee0a0012d02091b40egc ALINK="#FF0000"
d73ae94e59c019f5cc3221ee0a0012d02091b40egc<!--#include virtual="header.html" -->
d73ae94e59c019f5cc3221ee0a0012d02091b40egc<p>Many operating systems provide a facility for storage and
d73ae94e59c019f5cc3221ee0a0012d02091b40egctransmission of information called environment variables. Apache uses
d73ae94e59c019f5cc3221ee0a0012d02091b40egcenvironment variables in many ways to control operations and to
d73ae94e59c019f5cc3221ee0a0012d02091b40egccommunicate with other programs like CGI scripts. This document
d73ae94e59c019f5cc3221ee0a0012d02091b40egcexplains some of the ways to use environment variables in Apache.</p>
d73ae94e59c019f5cc3221ee0a0012d02091b40egc<li><a href="#setting">Setting Environment Variables</a></li>
e2c88f0c2610f16de7b639746b40dea5f3e2256eGarrett D'Amore<li><a href="#special">Special Purpose Environment Variables</a></li>
d73ae94e59c019f5cc3221ee0a0012d02091b40egc<h2><a name="setting">Setting Environment Variables</a></h2>
d73ae94e59c019f5cc3221ee0a0012d02091b40egc<A HREF="mod/mod_setenvif.html#BrowserMatch">BrowserMatch</A><br>
d73ae94e59c019f5cc3221ee0a0012d02091b40egc<A HREF="mod/mod_setenvif.html#BrowserMatchNoCase">BrowserMatchNoCase</A><br>
d73ae94e59c019f5cc3221ee0a0012d02091b40egc<A HREF="mod/mod_rewrite.html#RewriteRule">RewriteRule</A><br>
d73ae94e59c019f5cc3221ee0a0012d02091b40egc<A HREF="mod/mod_setenvif.html#SetEnvIfNoCase">SetEnvIfNoCase</A><br>
d73ae94e59c019f5cc3221ee0a0012d02091b40egc<p>The most basic way to set an environment variable in Apache is
d73ae94e59c019f5cc3221ee0a0012d02091b40egcusing the unconditional <code>SetEnv</code> directive. Variables
d73ae94e59c019f5cc3221ee0a0012d02091b40egcmay also be passed from the environment of the shell which started
d73ae94e59c019f5cc3221ee0a0012d02091b40egc<p>For additional flexibility, the directives provided by mod_setenvif
d73ae94e59c019f5cc3221ee0a0012d02091b40egcallow environment variables to be set on a per-request basis,
d73ae94e59c019f5cc3221ee0a0012d02091b40egcconditional on characteristics of particular requests. For example, a
d73ae94e59c019f5cc3221ee0a0012d02091b40egcvariable could be set only when a specific browser (User-Agent) is
d73ae94e59c019f5cc3221ee0a0012d02091b40egcmaking a request, or only when a specific Referer [sic] header is
d73ae94e59c019f5cc3221ee0a0012d02091b40egcfound. Even more flexibility is available through the mod_rewrite's
d73ae94e59c019f5cc3221ee0a0012d02091b40egc<code>RewriteRule</code> which uses the <code>[E=...]</code> option to
d73ae94e59c019f5cc3221ee0a0012d02091b40egcset environment variables.</p>
d73ae94e59c019f5cc3221ee0a0012d02091b40egc<p>Finally, mod_unique_id sets the environment variable
d73ae94e59c019f5cc3221ee0a0012d02091b40egc<code>UNIQUE_ID</code> for each request to a value which is guaranteed
d73ae94e59c019f5cc3221ee0a0012d02091b40egcto be unique across "all" requests under very specific conditions.</p>
d73ae94e59c019f5cc3221ee0a0012d02091b40egc<p>In addition to all environment variables set within the Apache
d73ae94e59c019f5cc3221ee0a0012d02091b40egcconfiguration and passed from the shell, CGI scripts and SSI pages are
d73ae94e59c019f5cc3221ee0a0012d02091b40egcprovided with a set of environment variables containing
d73ae94e59c019f5cc3221ee0a0012d02091b40egcmeta-information about the request as required by the <a
d73ae94e59c019f5cc3221ee0a0012d02091b40egc<li>It is not possible to override or change the standard CGI
d73ae94e59c019f5cc3221ee0a0012d02091b40egcvariables using the environment manipulation directives.</li>
d73ae94e59c019f5cc3221ee0a0012d02091b40egc<li>When <a href="suexec.html">suexec</a> is used to launch CGI
d73ae94e59c019f5cc3221ee0a0012d02091b40egcscripts, the environment will be cleaned down to a set of
d73ae94e59c019f5cc3221ee0a0012d02091b40egc<em>safe</em> variables before CGI scripts are launched. The list of
d73ae94e59c019f5cc3221ee0a0012d02091b40egc<li>For portability reasons, the names of environment variables
d73ae94e59c019f5cc3221ee0a0012d02091b40egcmay contain only letters, numbers, and the underscore character.
d73ae94e59c019f5cc3221ee0a0012d02091b40egcIn addition, the first character may not be a number. Characters
d73ae94e59c019f5cc3221ee0a0012d02091b40egcwhich do not match this restriction will be replaced by an
d73ae94e59c019f5cc3221ee0a0012d02091b40egcunderscore when passed to CGI scripts and SSI pages.</li>
d73ae94e59c019f5cc3221ee0a0012d02091b40egc<a href="mod/mod_log_config.html#customlog">CustomLog</a><br>
d73ae94e59c019f5cc3221ee0a0012d02091b40egc<a href="mod/mod_log_config.html#logformat">LogFormat</a><br>
d73ae94e59c019f5cc3221ee0a0012d02091b40egc<A HREF="mod/mod_rewrite.html#RewriteCond">RewriteCond</A><br>
d73ae94e59c019f5cc3221ee0a0012d02091b40egc<A HREF="mod/mod_rewrite.html#RewriteRule">RewriteRule</A><br>
d73ae94e59c019f5cc3221ee0a0012d02091b40egc<p>One of the primary uses of environment variables is to communicate
d73ae94e59c019f5cc3221ee0a0012d02091b40egcinformation to CGI scripts. As discussed above, the environment
d73ae94e59c019f5cc3221ee0a0012d02091b40egcpassed to CGI scripts includes standard meta-information about the request
d73ae94e59c019f5cc3221ee0a0012d02091b40egcin addition to any variables set within the Apache configuration.
d73ae94e59c019f5cc3221ee0a0012d02091b40egcFor more details, see the <a href="howto/cgi.html">CGI tutorial</a>.
# The first directive disables keepalive for Netscape 2.x and browsers that
SetEnvIf Referer "^http://www.example.com/" local_referal
<!--#include virtual="footer.html" -->