env.html revision 17bc0e8f2e3816e25bc8fd3fadf39357340aebd0
f743002678eb67b99bbc29fee116b65d9530fec0wrowe<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
80833bb9a1bf25dcf19e814438a4b311d2e1f4cffuankg "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5c43d2fb853f84497b5ece2d414ef9484aa87e5fsf
bd3f5647b96d378d9c75c954e3f13582af32c643sf<html xmlns="http://www.w3.org/1999/xhtml">
bd3f5647b96d378d9c75c954e3f13582af32c643sf <head>
bd3f5647b96d378d9c75c954e3f13582af32c643sf <meta name="generator" content="HTML Tidy, see www.w3.org" />
bd3f5647b96d378d9c75c954e3f13582af32c643sf
bd3f5647b96d378d9c75c954e3f13582af32c643sf <title>Environment Variables in Apache</title>
9e430d18dde58791589bd699416c8319560dd067jim </head>
9e430d18dde58791589bd699416c8319560dd067jim <!-- Background white, links blue (unvisited), navy (visited), red (active) -->
9e430d18dde58791589bd699416c8319560dd067jim
d03c146b3cdb757b2e7cb85881df1088558293a7covener <body bgcolor="#FFFFFF" text="#000000" link="#0000FF"
28cfe7f444531a5faf01669fac53a0e3280bf902covener vlink="#000080" alink="#FF0000">
d03c146b3cdb757b2e7cb85881df1088558293a7covener <!--#include virtual="header.html" -->
28cfe7f444531a5faf01669fac53a0e3280bf902covener
28cfe7f444531a5faf01669fac53a0e3280bf902covener <h1 align="center">Environment Variables in Apache</h1>
ad98610a7a84dfe5c967bf48470c0ef9788eab75covener
bf2c5978346829f62a64d3f2106a3cc08782b86csf <p>The Apache HTTP Server provides a mechanism for storing
bf2c5978346829f62a64d3f2106a3cc08782b86csf information in named variables that are called <em>environment
bf2c5978346829f62a64d3f2106a3cc08782b86csf variables</em>. This information can be used to control various
584a85dd4047e38d3ed3a29b6662fcc9d100ae4csf operations such as logging or access control. The variables are
584a85dd4047e38d3ed3a29b6662fcc9d100ae4csf also used as a mechanism to communicate with external programs
584a85dd4047e38d3ed3a29b6662fcc9d100ae4csf such as CGI scripts. This document discusses different ways to
855d6aa9f641cd160ee4265824a3ad3d06231c76covener manipulate and use these variables.</p>
855d6aa9f641cd160ee4265824a3ad3d06231c76covener
855d6aa9f641cd160ee4265824a3ad3d06231c76covener <p>Although these variables are referred to as <em>environment
855d6aa9f641cd160ee4265824a3ad3d06231c76covener variables</em>, they are not the same as the environment
ca8584db70d0ff4d85cbfd912573688c41be27cfjailletc variables controlled by the underlying operating system.
ca8584db70d0ff4d85cbfd912573688c41be27cfjailletc Instead, these variables are stored and manipulated in an
ca8584db70d0ff4d85cbfd912573688c41be27cfjailletc internal Apache structure. They only become actual operating
f21e9e3d0bfb7a507ecc5bc963f2159d693503d1sf system environment variables when they are provided to CGI
f21e9e3d0bfb7a507ecc5bc963f2159d693503d1sf scripts and Server Side Include scripts. If you wish to
f21e9e3d0bfb7a507ecc5bc963f2159d693503d1sf manipulate the operating system environment under which the
7f40ab64e74b7d1057b5ee6abc349e32e74b1b4cjim server itself runs, you must use the standard environment
7f40ab64e74b7d1057b5ee6abc349e32e74b1b4cjim manipulation mechanisms provided by your operating system
7f40ab64e74b7d1057b5ee6abc349e32e74b1b4cjim shell.</p>
f6b9c755a0b793e8a3a3aebd327ca20a86478117sf
f6b9c755a0b793e8a3a3aebd327ca20a86478117sf <ul>
f6b9c755a0b793e8a3a3aebd327ca20a86478117sf <li><a href="#setting">Setting Environment Variables</a></li>
132ee6ac1c26d6e8953836316ba50734eefab47bsf
132ee6ac1c26d6e8953836316ba50734eefab47bsf <li><a href="#using">Using Environment Variables</a></li>
132ee6ac1c26d6e8953836316ba50734eefab47bsf
132ee6ac1c26d6e8953836316ba50734eefab47bsf <li><a href="#special">Special Purpose Environment
497e47ed2aaf97b229bd29a8bdd15f5927dc50e6sf Variables</a></li>
497e47ed2aaf97b229bd29a8bdd15f5927dc50e6sf
5c43d2fb853f84497b5ece2d414ef9484aa87e5fsf <li><a href="#examples">Examples</a></li>
5c43d2fb853f84497b5ece2d414ef9484aa87e5fsf </ul>
5c43d2fb853f84497b5ece2d414ef9484aa87e5fsf <hr />
5c43d2fb853f84497b5ece2d414ef9484aa87e5fsf
4f517d09c93a552f177f49ff97e93aa44eb127ebcovener <h2><a id="setting" name="setting">Setting Environment
4f517d09c93a552f177f49ff97e93aa44eb127ebcovener Variables</a></h2>
4f517d09c93a552f177f49ff97e93aa44eb127ebcovener
4f517d09c93a552f177f49ff97e93aa44eb127ebcovener <table border="1">
6736c640e65e06990ef33af71ee81fac4df4ff5fjim <tr>
20eead0b01d51fce0cc17d04b8f98ec38eac68aejim <td valign="top"><strong>Related Modules</strong><br />
20eead0b01d51fce0cc17d04b8f98ec38eac68aejim <br />
20eead0b01d51fce0cc17d04b8f98ec38eac68aejim <a href="mod/mod_env.html">mod_env</a><br />
cc45ee60ddfb8380b3703455098475eb72625ca8jim <a href="mod/mod_rewrite.html">mod_rewrite</a><br />
20eead0b01d51fce0cc17d04b8f98ec38eac68aejim <a href="mod/mod_setenvif.html">mod_setenvif</a><br />
cc45ee60ddfb8380b3703455098475eb72625ca8jim <a href="mod/mod_unique_id.html">mod_unique_id</a><br />
cc45ee60ddfb8380b3703455098475eb72625ca8jim </td>
46e5dfe0899face9346d6711e4f2ba873d526991sf
46e5dfe0899face9346d6711e4f2ba873d526991sf <td valign="top"><strong>Related Directives</strong><br />
46e5dfe0899face9346d6711e4f2ba873d526991sf <br />
aee831691bb9ecd96dea63d35bc8bdd21c0f0b1fsf <a
aee831691bb9ecd96dea63d35bc8bdd21c0f0b1fsf href="mod/mod_setenvif.html#BrowserMatch">BrowserMatch</a><br />
aee831691bb9ecd96dea63d35bc8bdd21c0f0b1fsf <a
aee831691bb9ecd96dea63d35bc8bdd21c0f0b1fsf href="mod/mod_setenvif.html#BrowserMatchNoCase">BrowserMatchNoCase</a><br />
79ccc75d7de4e14e5add1fa73aaabda0f5d33fe6trawick <a href="mod/mod_env.html#passenv">PassEnv</a><br />
79ccc75d7de4e14e5add1fa73aaabda0f5d33fe6trawick <a
79ccc75d7de4e14e5add1fa73aaabda0f5d33fe6trawick href="mod/mod_rewrite.html#RewriteRule">RewriteRule</a><br />
fc1459657a1fde206a847f9028930725d715f8b4trawick <a href="mod/mod_env.html#setenv">SetEnv</a><br />
fc1459657a1fde206a847f9028930725d715f8b4trawick <a
fc1459657a1fde206a847f9028930725d715f8b4trawick href="mod/mod_setenvif.html#SetEnvIf">SetEnvIf</a><br />
e758971371df73b097609b2fd62bc14ad935e096trawick <a
e758971371df73b097609b2fd62bc14ad935e096trawick href="mod/mod_setenvif.html#SetEnvIfNoCase">SetEnvIfNoCase</a><br />
e758971371df73b097609b2fd62bc14ad935e096trawick <a href="mod/mod_env.html#unsetenv">UnsetEnv</a><br />
1dd5136d67e0164e4afd723a471b86a1b7eb1874sf </td>
1dd5136d67e0164e4afd723a471b86a1b7eb1874sf </tr>
1dd5136d67e0164e4afd723a471b86a1b7eb1874sf </table>
1dd5136d67e0164e4afd723a471b86a1b7eb1874sf
e39eb98e3ad3fbf5c34b2fa1d16861f95143e22esf <h3>Basic Environment Manipulation</h3>
e39eb98e3ad3fbf5c34b2fa1d16861f95143e22esf
e39eb98e3ad3fbf5c34b2fa1d16861f95143e22esf <p>The most basic way to set an environment variable in Apache
d6fc66efa723db8b3ee5e9fd32579bed884e4e58sf is using the unconditional <code>SetEnv</code> directive.
d6fc66efa723db8b3ee5e9fd32579bed884e4e58sf Variables may also be passed from the environment of the shell
d6fc66efa723db8b3ee5e9fd32579bed884e4e58sf which started the server using the <code>PassEnv</code>
d6fc66efa723db8b3ee5e9fd32579bed884e4e58sf directive.</p>
f00cb80197f824c3ff00dd4fdff3b2c267a519d1kbrand
f00cb80197f824c3ff00dd4fdff3b2c267a519d1kbrand <h3>Conditional Per-Request Settings</h3>
f00cb80197f824c3ff00dd4fdff3b2c267a519d1kbrand
f00cb80197f824c3ff00dd4fdff3b2c267a519d1kbrand <p>For additional flexibility, the directives provided by
85eacfc96a04547ef25aabbc06440039715084c2jorton mod_setenvif allow environment variables to be set on a
85eacfc96a04547ef25aabbc06440039715084c2jorton per-request basis, conditional on characteristics of particular
85eacfc96a04547ef25aabbc06440039715084c2jorton requests. For example, a variable could be set only when a
1d8d7e58e1d31d7b6fb7a518e09649a4dbb315e9trawick specific browser (User-Agent) is making a request, or only when
1d8d7e58e1d31d7b6fb7a518e09649a4dbb315e9trawick a specific Referer [sic] header is found. Even more flexibility
1d8d7e58e1d31d7b6fb7a518e09649a4dbb315e9trawick is available through the mod_rewrite's <code>RewriteRule</code>
f34da68471f256dca0ff770257c3e1f982f74cf1trawick which uses the <code>[E=...]</code> option to set environment
f34da68471f256dca0ff770257c3e1f982f74cf1trawick variables.</p>
f34da68471f256dca0ff770257c3e1f982f74cf1trawick
8b645fd3c950da73513b546366c7cfa7476c5c06jim <h3>Unique Identifiers</h3>
8b645fd3c950da73513b546366c7cfa7476c5c06jim
8b645fd3c950da73513b546366c7cfa7476c5c06jim <p>Finally, mod_unique_id sets the environment variable
8b645fd3c950da73513b546366c7cfa7476c5c06jim <code>UNIQUE_ID</code> for each request to a value which is
193f0bb6057d67593ed652fbf58f043def51c642jim guaranteed to be unique across "all" requests under very
193f0bb6057d67593ed652fbf58f043def51c642jim specific conditions.</p>
193f0bb6057d67593ed652fbf58f043def51c642jim
68ba377fc3b124baa759662077c48077ebadb186minfrin <h3>Standard CGI Variables</h3>
68ba377fc3b124baa759662077c48077ebadb186minfrin
68ba377fc3b124baa759662077c48077ebadb186minfrin <p>In addition to all environment variables set within the
68ba377fc3b124baa759662077c48077ebadb186minfrin Apache configuration and passed from the shell, CGI scripts and
00566fb187849626180724394a21ddcd28419fb2minfrin SSI pages are provided with a set of environment variables
00566fb187849626180724394a21ddcd28419fb2minfrin containing meta-information about the request as required by
00566fb187849626180724394a21ddcd28419fb2minfrin the <a href="http://cgi-spec.golux.com/">CGI
00566fb187849626180724394a21ddcd28419fb2minfrin specification</a>.</p>
d776b0a2d2889ce1d13494873368f34327a2e1bbtrawick
d776b0a2d2889ce1d13494873368f34327a2e1bbtrawick <h3>Some Caveats</h3>
f4ca9f6f002fece336168a16355434ca966f96a9trawick
57db302f0875a6c93a79333b8941cea4c1827272jim <ul>
57db302f0875a6c93a79333b8941cea4c1827272jim <li>It is not possible to override or change the standard CGI
57db302f0875a6c93a79333b8941cea4c1827272jim variables using the environment manipulation directives.</li>
57db302f0875a6c93a79333b8941cea4c1827272jim
92b1631880b0bf43fe8b2663a03c8571eb04e433jim <li>When <a href="suexec.html">suexec</a> is used to launch
92b1631880b0bf43fe8b2663a03c8571eb04e433jim CGI scripts, the environment will be cleaned down to a set of
92b1631880b0bf43fe8b2663a03c8571eb04e433jim <em>safe</em> variables before CGI scripts are launched. The
89225e8e84d38b07a8335922497997e83d872e75jim list of <em>safe</em> variables is defined at compile-time in
89225e8e84d38b07a8335922497997e83d872e75jim <code>suexec.c</code>.</li>
89225e8e84d38b07a8335922497997e83d872e75jim
78f94f1d06c4e6828ce04d618221e0fcecb57849humbedooh <li>For portability reasons, the names of environment
78f94f1d06c4e6828ce04d618221e0fcecb57849humbedooh variables may contain only letters, numbers, and the
78f94f1d06c4e6828ce04d618221e0fcecb57849humbedooh underscore character. In addition, the first character may
f5e28c78424d2f71c61ba457009f100bba38bc68chrisd not be a number. Characters which do not match this
f5e28c78424d2f71c61ba457009f100bba38bc68chrisd restriction will be replaced by an underscore when passed to
f5e28c78424d2f71c61ba457009f100bba38bc68chrisd CGI scripts and SSI pages.</li>
f4a715f904b014060ea6237fe29481ed21f5c7d0jorton </ul>
f4a715f904b014060ea6237fe29481ed21f5c7d0jorton <hr />
f4a715f904b014060ea6237fe29481ed21f5c7d0jorton
536d2e7cd1fdec1255b8c3bdf41fdc714c506a54trawick <h2><a id="using" name="using">Using Environment
536d2e7cd1fdec1255b8c3bdf41fdc714c506a54trawick Variables</a></h2>
536d2e7cd1fdec1255b8c3bdf41fdc714c506a54trawick
536d2e7cd1fdec1255b8c3bdf41fdc714c506a54trawick <table border="1">
70caa242e6b90e0d6f0fabb56b8c5c2fb51717b3jorton <tr>
985a4368b93c3e9171a57897ad9454c8dbf4cdf6jorton <td valign="top"><strong>Related Modules</strong><br />
70caa242e6b90e0d6f0fabb56b8c5c2fb51717b3jorton <br />
70caa242e6b90e0d6f0fabb56b8c5c2fb51717b3jorton <a href="mod/mod_access.html">mod_access</a><br />
109e2a09790de3fb315d36d6232a14ab66c8eb0ahumbedooh <a href="mod/mod_cgi.html">mod_cgi</a><br />
109e2a09790de3fb315d36d6232a14ab66c8eb0ahumbedooh <a href="mod/mod_headers.html">mod_headers</a><br />
109e2a09790de3fb315d36d6232a14ab66c8eb0ahumbedooh <a href="mod/mod_include.html">mod_include</a><br />
4be250c774bdac977eef29a02183ca78de29fb41rjung <a href="mod/mod_log_config.html">mod_log_config</a><br />
4be250c774bdac977eef29a02183ca78de29fb41rjung <a href="mod/mod_rewrite.html">mod_rewrite</a><br />
4be250c774bdac977eef29a02183ca78de29fb41rjung </td>
12b5dc9afa1844df5ac8acab98fb538432a2fa1crjung
12b5dc9afa1844df5ac8acab98fb538432a2fa1crjung <td valign="top"><strong>Related Directives</strong><br />
12b5dc9afa1844df5ac8acab98fb538432a2fa1crjung <br />
12b5dc9afa1844df5ac8acab98fb538432a2fa1crjung <a href="mod/mod_access.html#allow">Allow</a><br />
74e7a30182af5e68f14ccb8d57918b22b982db8bhumbedooh <a
74e7a30182af5e68f14ccb8d57918b22b982db8bhumbedooh href="mod/mod_log_config.html#customlog">CustomLog</a><br />
74e7a30182af5e68f14ccb8d57918b22b982db8bhumbedooh <a href="mod/mod_access.html#deny">Deny</a><br />
10961a2f60207cb873d889bb28b1f0ef707a4311humbedooh <a href="mod/mod_headers.html#Header">Header</a><br />
10961a2f60207cb873d889bb28b1f0ef707a4311humbedooh <a
10961a2f60207cb873d889bb28b1f0ef707a4311humbedooh href="mod/mod_log_config.html#logformat">LogFormat</a><br />
0448378b899e8df0c060360f17c0af692adf17bchumbedooh <a
0448378b899e8df0c060360f17c0af692adf17bchumbedooh href="mod/mod_rewrite.html#RewriteCond">RewriteCond</a><br />
0448378b899e8df0c060360f17c0af692adf17bchumbedooh <a
60a765cccbd3f3b5997b65b0034220c79f78369etrawick href="mod/mod_rewrite.html#RewriteRule">RewriteRule</a><br />
60a765cccbd3f3b5997b65b0034220c79f78369etrawick </td>
60a765cccbd3f3b5997b65b0034220c79f78369etrawick </tr>
e7ca863b04ee2a7aea7738cadbf51ce5e6c5245dhumbedooh </table>
e7ca863b04ee2a7aea7738cadbf51ce5e6c5245dhumbedooh
e7ca863b04ee2a7aea7738cadbf51ce5e6c5245dhumbedooh <h3>CGI Scripts</h3>
e7ca863b04ee2a7aea7738cadbf51ce5e6c5245dhumbedooh
91654e263480f0fdc2a03d782ff23f8dad07cf79humbedooh <p>One of the primary uses of environment variables is to
91814c869ca39ce45dfe147307d2a831cac6ecbehumbedooh communicate information to CGI scripts. As discussed above, the
91654e263480f0fdc2a03d782ff23f8dad07cf79humbedooh environment passed to CGI scripts includes standard
79c5787b92ac5f0e1cc82393816c77a006399316trawick meta-information about the request in addition to any variables
79c5787b92ac5f0e1cc82393816c77a006399316trawick set within the Apache configuration. For more details, see the
79c5787b92ac5f0e1cc82393816c77a006399316trawick <a href="howto/cgi.html">CGI tutorial</a>.</p>
79c5787b92ac5f0e1cc82393816c77a006399316trawick
c967bf3bc89e8aa60dbd30d9da388e448ddc1cc4trawick <h3>SSI Pages</h3>
79c5787b92ac5f0e1cc82393816c77a006399316trawick
79c5787b92ac5f0e1cc82393816c77a006399316trawick <p>Server-parsed (SSI) documents processed by mod_include's
79c5787b92ac5f0e1cc82393816c77a006399316trawick <code>INCLUDES</code> filter can print environment variables
79c5787b92ac5f0e1cc82393816c77a006399316trawick using the <code>echo</code> element, and can use environment
79c5787b92ac5f0e1cc82393816c77a006399316trawick variables in flow control elements to makes parts of a page
12b987b969f03ef98d9175a53d849ab62f5684fecovener conditional on characteristics of a request. Apache also
12b987b969f03ef98d9175a53d849ab62f5684fecovener provides SSI pages with the standard CGI environment variables
099c357f282d4aebf2b32264f7dce6ffc0497c37sf as discussed above. For more details, see the <a
099c357f282d4aebf2b32264f7dce6ffc0497c37sf href="howto/ssi.html">SSI tutorial</a>.</p>
099c357f282d4aebf2b32264f7dce6ffc0497c37sf
099c357f282d4aebf2b32264f7dce6ffc0497c37sf <h3>Access Control</h3>
50f8c80eb4d3989ebf3f1341aeef4d2d302af162sf
50f8c80eb4d3989ebf3f1341aeef4d2d302af162sf <p>Access to the server can be controlled based on the value of
4bb0a88a01fb7b494bb02a8b881b5eab0308bda6sf environment variables using the <code>allow from env=</code>
50f8c80eb4d3989ebf3f1341aeef4d2d302af162sf and <code>deny from env=</code> directives. In combination with
7b395e4e878c28a4784919cfd2e704ddd14a3390jorton <code>SetEnvIf</code>, this allows for flexible control of
7b395e4e878c28a4784919cfd2e704ddd14a3390jorton access to the server based on characteristics of the client.
7b395e4e878c28a4784919cfd2e704ddd14a3390jorton For example, you can use these directives to deny access to a
7b395e4e878c28a4784919cfd2e704ddd14a3390jorton particular browser (User-Agent).</p>
536e48c08d674acac5d44929318f2ad928edc361jorton
536e48c08d674acac5d44929318f2ad928edc361jorton <h3>Conditional Logging</h3>
e81785da447b469da66f218b3f0244aab507958djorton
e81785da447b469da66f218b3f0244aab507958djorton <p>Environment variables can be logged in the access log using
3e4e54d4e3fc0123c63d57aa84ac7ad7a8c73ff8jorton the <code>LogFormat</code> option <code>%e</code>. In addition,
3e4e54d4e3fc0123c63d57aa84ac7ad7a8c73ff8jorton the decision on whether or not to log requests can be made
3e4e54d4e3fc0123c63d57aa84ac7ad7a8c73ff8jorton based on the status of environment variables using the
459eaf0826f995b73a0dc066f59ea10d2824e72dsf conditional form of the <code>CustomLog</code> directive. In
459eaf0826f995b73a0dc066f59ea10d2824e72dsf combination with <code>SetEnvIf</code> this allows for flexible
459eaf0826f995b73a0dc066f59ea10d2824e72dsf control of which requests are logged. For example, you can
459eaf0826f995b73a0dc066f59ea10d2824e72dsf choose not to log requests for filenames ending in
53e9b27aba029b18be814df40bcf6f0428771d1efuankg <code>gif</code>, or you can choose to only log requests from
53e9b27aba029b18be814df40bcf6f0428771d1efuankg clients which are outside your subnet.</p>
53e9b27aba029b18be814df40bcf6f0428771d1efuankg
53e9b27aba029b18be814df40bcf6f0428771d1efuankg <h3>Conditional Response Headers</h3>
53e9b27aba029b18be814df40bcf6f0428771d1efuankg
6bb524f1895f30265a1431afc460977d391cb36bsf <p>The <code>Header</code> directive can use the presence or
6bb524f1895f30265a1431afc460977d391cb36bsf absence of an environment variable to determine whether or not
ca61ccd0c306c2c72df153688ba1b49f3eceed80sf a certain HTTP header will be placed in the response to the
6bb524f1895f30265a1431afc460977d391cb36bsf client. This allows, for example, a certain response header to
e6dd71992459d05a676b98b7963423dc5dc1e24aminfrin be sent only if a corresponding header is received in the
e6dd71992459d05a676b98b7963423dc5dc1e24aminfrin request from the client.</p>
e6dd71992459d05a676b98b7963423dc5dc1e24aminfrin
e6dd71992459d05a676b98b7963423dc5dc1e24aminfrin <h3>URL Rewriting</h3>
23f1535d6a60817d2846bac0aea230ea475d7dccminfrin
23f1535d6a60817d2846bac0aea230ea475d7dccminfrin <p>The <code>%{ENV:...}</code> form of <em>TestString</em> in
23f1535d6a60817d2846bac0aea230ea475d7dccminfrin the <code>RewriteCond</code> allows mod_rewrite's rewrite
23f1535d6a60817d2846bac0aea230ea475d7dccminfrin engine to make decisions conditional on environment variables.
ec7520b24cd80d34d82bbcaca153cbb23cc04bc0rjung Note that the variables accessible in mod_rewrite without the
ec7520b24cd80d34d82bbcaca153cbb23cc04bc0rjung <code>ENV:</code> prefix are not actually environment
ec7520b24cd80d34d82bbcaca153cbb23cc04bc0rjung variables. Rather, they are variables special to mod_rewrite
ec7520b24cd80d34d82bbcaca153cbb23cc04bc0rjung which cannot be accessed from other modules.</p>
ec7520b24cd80d34d82bbcaca153cbb23cc04bc0rjung <hr />
ec7520b24cd80d34d82bbcaca153cbb23cc04bc0rjung
ec7520b24cd80d34d82bbcaca153cbb23cc04bc0rjung <h2><a id="special" name="special">Special Purpose Environment
ec7520b24cd80d34d82bbcaca153cbb23cc04bc0rjung Variables</a></h2>
6249dfa569d3b4f1f539665b979a80c6e335d93etrawick
6249dfa569d3b4f1f539665b979a80c6e335d93etrawick <p>Interoperability problems have led to the introduction of
0827cb14e550f6f65018431c22c2c913631c8f25kbrand mechanisms to modify the way Apache behaves when talking to
6249dfa569d3b4f1f539665b979a80c6e335d93etrawick particular clients. To make these mechanisms as flexible as
ae600ca541efc686b34f8b1f21bd3d0741d37674covener possible, they are invoked by defining environment variables,
6249dfa569d3b4f1f539665b979a80c6e335d93etrawick typically with <a
cfa64348224b66dd1c9979b809406c4d15b1c137fielding href="mod/mod_setenvif.html#browsermatch">BrowserMatch</a>,
74499a117b3b2cd9666715a14f90c0e5d1a4ee8ajim though <a href="mod/mod_env.html#setenv">SetEnv</a> and <a
cfa64348224b66dd1c9979b809406c4d15b1c137fielding href="mod/mod_env.html#passenv">PassEnv</a> could also be used,
74499a117b3b2cd9666715a14f90c0e5d1a4ee8ajim for example.</p>
cfa64348224b66dd1c9979b809406c4d15b1c137fielding
74499a117b3b2cd9666715a14f90c0e5d1a4ee8ajim <h2>downgrade-1.0</h2>
cfa64348224b66dd1c9979b809406c4d15b1c137fielding
74499a117b3b2cd9666715a14f90c0e5d1a4ee8ajim <p>This forces the request to be treated as a HTTP/1.0 request
cfa64348224b66dd1c9979b809406c4d15b1c137fielding even if it was in a later dialect.</p>
<h2>force-no-vary</h2>
<p>This causes any <code>Vary</code> fields to be removed from
the response header before it is sent back to the client. Some
clients don't interpret this field correctly (see the <a
href="misc/known_client_problems.html">known client
problems</a> page); setting this variable can work around this
problem. Setting this variable also implies
<strong>force-response-1.0</strong>.</p>
<h2>force-response-1.0</h2>
<p>This forces an HTTP/1.0 response when set. It was originally
implemented as a result of a problem with AOL's proxies. Some
clients may not behave correctly when given an HTTP/1.1
response, and this can be used to interoperate with them.</p>
<h2>nokeepalive</h2>
<p>This disables <a
href="mod/core.html#keepalive">KeepAlive</a> when set.</p>
<h2>redirect-carefully</h2>
<p>This forces the server to be more careful when sending a redirect
to the client. This is typically used when a client has a known
problem handling redirects. This was originally implemented as a
result of a problem with Microsoft's WebFolders software which has
a problem handling redirects on directory resources via DAV
methods.</p>
<hr />
<h2><a id="examples" name="examples">Examples</a></h2>
<h3>Changing protocol behavior with misbehaving clients</h3>
<p>We recommend that the following lines be included in
httpd.conf to deal with known client problems.</p>
<pre>
#
# The following directives modify normal HTTP response behavior.
# The first directive disables keepalive for Netscape 2.x and browsers that
# spoof it. There are known problems with these browser implementations.
# The second directive is for Microsoft Internet Explorer 4.0b2
# which has a broken HTTP/1.1 implementation and does not properly
# support keepalive when it is used on 301 or 302 (redirect) responses.
#
BrowserMatch "Mozilla/2" nokeepalive
BrowserMatch "MSIE 4\.0b2;" nokeepalive downgrade-1.0 force-response-1.0
#
# The following directive disables HTTP/1.1 responses to browsers which
# are in violation of the HTTP/1.0 spec by not being able to grok a
# basic 1.1 response.
#
BrowserMatch "RealPlayer 4\.0" force-response-1.0
BrowserMatch "Java/1\.0" force-response-1.0
BrowserMatch "JDK/1\.0" force-response-1.0
</pre>
<h3>Do not log requests for images in the access log</h3>
<p>This example keeps requests for images from appearing in the
access log. It can be easily modified to prevent logging of
particular directories, or to prevent logging of requests
coming from particular hosts.</p>
<pre>
SetEnvIf Request_URI \.gif image-request
SetEnvIf Request_URI \.jpg image-request
SetEnvIf Request_URI \.png image-request
CustomLog logs/access_log env=!image-request
</pre>
<h3>Prevent "Image Theft"</h3>
<p>This example shows how to keep people not on your server
from using images on your server as inline-images on their
pages. This is not a recommended configuration, but it can work
in limited circumstances. We assume that all your images are in
a directory called /web/images.</p>
<pre>
SetEnvIf Referer "^http://www.example.com/" local_referal
# Allow browsers that do not send Referer info
SetEnvIf Referer "^$" local_referal
&lt;Directory /web/images&gt;
Order Deny,Allow
Deny from all
Allow from env=local_referal
&lt;/Directory&gt;
</pre>
<p>For more information about this technique, see the
ApacheToday tutorial " <a
href="http://apachetoday.com/news_story.php3?ltsn=2000-06-14-002-01-PS">
Keeping Your Images from Adorning Other Sites</a>".</p>
<!--#include virtual="footer.html" -->
</body>
</html>