expr.html.en revision c11bfe6804eff2f4c7054cf2f7b06f0c8b32e596
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!--
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd This file is generated from xml source: DO NOT EDIT
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<title>Expressions in Apache HTTP Server - Apache HTTP Server</title>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<link href="/style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<link href="/style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen<link href="/style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" /><link rel="stylesheet" type="text/css" href="/style/css/prettify.css" />
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen<script src="/style/scripts/prettify.js" type="text/javascript">
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<link href="/images/favicon.ico" rel="shortcut icon" /></head>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<p class="menu"><a href="/mod/">Modules</a> | <a href="/mod/directives.html">Directives</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="/glossary.html">Glossary</a> | <a href="/sitemap.html">Sitemap</a></p>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<div class="up"><a href="./"><img title="<-" alt="<-" src="/images/left.gif" /></a></div>
3f08db06526d6901aa08c110b5bc7dde6bc39905nd<a href="http://www.apache.org/">Apache</a> > <a href="http://httpd.apache.org/">HTTP Server</a> > <a href="http://httpd.apache.org/docs/">Documentation</a> > <a href="./">Version 2.5</a></div><div id="page-content"><div id="preamble"><h1>Expressions in Apache HTTP Server</h1>
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd<p><span>Available Languages: </span><a href="/en/expr.html" title="English"> en </a> |
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd<a href="/fr/expr.html" hreflang="fr" rel="alternate" title="Fran�ais"> fr </a></p>
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd <p>Historically, there are several syntax variants for expressions used to express
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end a condition in the different modules of the Apache HTTP Server.
d474d8ef01ec5c2a09341cd148851ed383c3287crbowen There is some ongoing effort to only use a single variant, called <em>ap_expr</em>,
d474d8ef01ec5c2a09341cd148851ed383c3287crbowen for all configuration directives.
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd This document describes the <em>ap_expr</em> expression parser.
4b575a6b6704b516f22d65a3ad35696d7b9ba372rpluem <p>The <em>ap_expr</em> expression is intended to replace most other
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd expression variants in HTTPD. For example, the deprecated
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd <code class="directive"><a href="/mod/mod_ssl.html#sslrequire">SSLRequire</a></code> expressions can be
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd replaced by <a href="mod/mod_authz_core.html#reqexpr">Require expr</a>.
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<div id="quickview"><ul id="toc"><li><img alt="" src="/images/down.gif" /> <a href="#grammar">Grammar in Backus-Naur Form notation</a></li>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<li><img alt="" src="/images/down.gif" /> <a href="#vars">Variables</a></li>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<li><img alt="" src="/images/down.gif" /> <a href="#binop">Binary operators</a></li>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<li><img alt="" src="/images/down.gif" /> <a href="#unnop">Unary operators</a></li>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<li><img alt="" src="/images/down.gif" /> <a href="#functions">Functions</a></li>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<li><img alt="" src="/images/down.gif" /> <a href="#examples">Example expressions</a></li>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<li><img alt="" src="/images/down.gif" /> <a href="#other">Other</a></li>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<li><img alt="" src="/images/down.gif" /> <a href="#sslrequire">Comparison with SSLRequire</a></li>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd</ul><h3>See also</h3><ul class="seealso"><li><code class="directive"><a href="/mod/core.html#if"><If></a></code></li><li><code class="directive"><a href="/mod/core.html#elseif"><ElseIf></a></code></li><li><code class="directive"><a href="/mod/core.html#else"><Else></a></code></li><li><code class="directive"><a href="/mod/mod_rewrite.html#rewritecond">RewriteCond</a></code></li><li><code class="directive"><a href="/mod/mod_setenvif.html#setenvifexpr">SetEnvIfExpr</a></code></li><li><code class="directive"><a href="/mod/mod_headers.html#header">Header</a></code></li><li><code class="directive"><a href="/mod/mod_headers.html#requestheader">RequestHeader</a></code></li><li><code class="directive"><a href="/mod/mod_filter.html#filterprovider">FilterProvider</a></code></li><li><a href="mod/mod_authz_core.html#reqexpr">Require expr</a></li><li><code class="directive"><a href="/mod/mod_ssl.html#sslrequire">SSLRequire</a></code></li><li><code class="directive"><a href="/mod/mod_log_debug.html#logmessage">LogMessage</a></code></li><li><code class="module"><a href="/mod/mod_include.html">mod_include</a></code></li></ul><ul class="seealso"><li><a href="#comments_section">Comments</a></li></ul></div>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<h2><a name="grammar" id="grammar">Grammar in Backus-Naur Form notation</a></h2>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd <p><a href="http://en.wikipedia.org/wiki/Backus%E2%80%93Naur_Form">Backus-Naur Form</a> (BNF) is a notation
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd technique for context-free grammars, often used to describe the syntax of languages used in computing.
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd In most cases, expressions are used to express boolean values.
80eed96ee3d8cfa0b66d9fb1cfe63fd83254d38bnilgun For these, the starting boint in the BNF is <code>expr</code>. However, a few directives
80eed96ee3d8cfa0b66d9fb1cfe63fd83254d38bnilgun like <code class="directive"><a href="/mod/mod_log_debug.html#logmessage">LogMessage</a></code> accept expressions
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd that evaluate to a string value. For those, the starting boint in the BNF is <code>code</code>.
316f02e3836836c82e19019ff23f90a7ebc65289nilgun<blockquote>
0853e1e2522c1ac17f697221758bcbd4781a7ff9ndexpr ::= "<strong>true</strong>" | "<strong>false</strong>"
b43f840409794ed298e8634f6284741f193b6c4ftakashicomp ::= stringcomp
22d5d84393d960a2027f472036f3fee15d7dbce9nd | integercomp
22d5d84393d960a2027f472036f3fee15d7dbce9nd | unaryop word
22d5d84393d960a2027f472036f3fee15d7dbce9nd | word binaryop word
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd | word "<strong>in</strong>" "<strong>{</strong>" wordlist "<strong>}</strong>"
a78048ccbdb6256da15e6b0e7e95355e480c2301ndintegercomp ::= word "<strong>-eq</strong>" word | word "<strong>eq</strong>" word
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe | word "<strong>-ne</strong>" word | word "<strong>ne</strong>" word
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe | word "<strong>-lt</strong>" word | word "<strong>lt</strong>" word
42af92a661a06b3cebc88d585aad75064a309d51nd | word "<strong>-le</strong>" word | word "<strong>le</strong>" word
42af92a661a06b3cebc88d585aad75064a309d51nd | word "<strong>-gt</strong>" word | word "<strong>gt</strong>" word
ffb88a4885747797937e30a5ac8b1606da3cb4adnd | word "<strong>-ge</strong>" word | word "<strong>ge</strong>" word
a78048ccbdb6256da15e6b0e7e95355e480c2301ndwordlist ::= word
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd | variable
08cf4a15275e4cb65a424b3a1db5410bfb51085cjim | rebackref
f5a398cc8880978754903f9ece8e4beb63a81cedrbowenstring ::= stringpart
f5a398cc8880978754903f9ece8e4beb63a81cedrbowen | string stringpart
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bndstringpart ::= cstring
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd | variable
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd | rebackref
7906201913b68fe78b9d6a22ab33bf21d82c490eminfrincstring ::= ...
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnddigit ::= [0-9]+
05ede5110427cb9dc071cc671d5aaba5d3b88c79ndvariable ::= "<strong>%{</strong>" varname "<strong>}</strong>"
e8b603fa9ccf7b17b11b42df6d8916fd97c2331dnd | "<strong>%{</strong>" funcname "<strong>:</strong>" funcargs "<strong>}</strong>"
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bndfunction ::= funcname "<strong>(</strong>" word "<strong>)</strong>"
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bndlistfunction ::= listfuncname "<strong>(</strong>" word "<strong>)</strong>"
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd</blockquote>
6aadbc6fd703e73d1d419e9f06b84a4338c898f1maczniak</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
03a4ff9ac4c9b8009249010e7c53bb86ff05915and <p>The expression parser provides a number of variables of the form
5effc8b39fae5cd169d17f342bfc265705840014rbowen <code>%{HTTP_HOST}</code>. Note that the value of a variable may depend
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak on the phase of the request processing in which it is evaluated. For
b43f840409794ed298e8634f6284741f193b6c4ftakashi example, an expression used in an <code class="directive"><If ></code>
b43f840409794ed298e8634f6284741f193b6c4ftakashi directive is evaluated before authentication is done. Therefore,
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak <code>%{REMOTE_USER}</code> will not be set in this case.</p>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd <p>The following variables provide the values of the named HTTP request
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak headers. The values of other headers can be obtained with the
6aadbc6fd703e73d1d419e9f06b84a4338c898f1maczniak <code>req</code> <a href="#functions">function</a>. Using these
2704de98885368683621b01c8f8f4e4b01557611takashi variables may cause the header name to be added to the Vary
2704de98885368683621b01c8f8f4e4b01557611takashi header of the HTTP response, except where otherwise noted for the
2704de98885368683621b01c8f8f4e4b01557611takashi directive accepting the expression.</p>
2704de98885368683621b01c8f8f4e4b01557611takashi <table class="bordered"><tr class="header"><th>Name</th></tr>
6aadbc6fd703e73d1d419e9f06b84a4338c898f1maczniak<tr class="odd"><td><code>HTTP_FORWARDED</code></td></tr>
d2b809e5d72658bff23819d8b77f20e4939af541nd<tr class="odd"><td><code>HTTP_PROXY_CONNECTION</code></td></tr>
4ed26c413f67a5aae20b95909828f30bb5dc2286poirier<tr class="odd"><td><code>HTTP_USER_AGENT</code></td></tr>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd <table class="bordered"><tr class="header"><th>Name</th><th>Description</th></tr>
28c9d384aa958b321280b4ac886941dcad25396bnd <td>The full local filesystem path to the file or script matching the
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd request, if this has already been determined by the server at the
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd time <code>REQUEST_FILENAME</code> is referenced. Otherwise, such
438b4817913a5ff55d9cad4c7ddf133330b4466ejim as when used in virtual host context, the same value as
1d980e5489836e977ba59b419e27b0ec875c4bd3takashi<tr class="odd"><td><code>SCRIPT_FILENAME</code></td>
50cb7e2b30597f481fee57bac945190f06ebcc58jorton <td>The date and time of last modification of the file in the format
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd <code>20101231235959</code>, if this has already been determined by
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd the server at the time <code>LAST_MODIFIED</code> is referenced.
4ed26c413f67a5aae20b95909828f30bb5dc2286poirier <td>The trailing path name information, see
5effc8b39fae5cd169d17f342bfc265705840014rbowen <code class="directive"><a href="/mod/core.html#acceptpathinfo">AcceptPathInfo</a></code></td></tr>
11495c9f0bd33e51a25b4d532beadfbcf9b944a3nilgun <td>"<code>true</code>" if the current request is a subrequest,
f772e8f448c223e5ea306f1bf92d97d968f972d5jim <td>The name of the authenticated user (if any)</td></tr>
1de1266f0ea387d6373be8415745dfd2ab876341jim <td>The user name set by <code class="module"><a href="/mod/mod_ident.html">mod_ident</a></code></td></tr>
a78048ccbdb6256da15e6b0e7e95355e480c2301nd <td>The <code class="directive"><a href="/mod/core.html#servername">ServerName</a></code> of
5effc8b39fae5cd169d17f342bfc265705840014rbowen <td>The server port of the current vhost, see
5effc8b39fae5cd169d17f342bfc265705840014rbowen <code class="directive"><a href="/mod/core.html#servername">ServerName</a></code></td></tr>
a78048ccbdb6256da15e6b0e7e95355e480c2301nd <td>The <code class="directive"><a href="/mod/core.html#serveradmin">ServerAdmin</a></code> of
a78048ccbdb6256da15e6b0e7e95355e480c2301nd <td>The <code class="directive"><a href="/mod/core.html#documentroot">DocumentRoot</a></code> of
50cb7e2b30597f481fee57bac945190f06ebcc58jorton <td>The configured <code class="directive"><a href="/mod/mod_authn_core.html#authtype">AuthType</a></code>
8e31885fc494b603e0650113dde9e29d1b1d2602maczniak <td>The name of the <a href="handler.html">handler</a> creating
ecc5150d35c0dc5ee5119c2717e6660fa331abbftakashi <td>The error log id of the request (see
bc9d4698fce0238d2f6f2682e99423ebb1149976rbowen <code class="directive"><a href="/mod/core.html#errorlogformat">ErrorLogFormat</a></code>)</td></tr>
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end <td>The error log id of the connection (see
d474d8ef01ec5c2a09341cd148851ed383c3287crbowen <code class="directive"><a href="/mod/core.html#errorlogformat">ErrorLogFormat</a></code>)</td></tr>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd <td>The peer IP address of the connection (see the
5effc8b39fae5cd169d17f342bfc265705840014rbowen <code class="module"><a href="/mod/mod_remoteip.html">mod_remoteip</a></code> module)</td></tr>
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen <table class="bordered"><tr class="header"><th>Name</th><th>Description</th></tr>
<p>Some modules register additional variables, see e.g. <code class="module"><a href="/mod/mod_ssl.html">mod_ssl</a></code>.</p>
<table class="bordered"><tr class="header"><th>Name</th><th>Alternative</th> <th>Description</th></tr>
<table class="bordered"><tr class="header"><th>Name</th><th>Description</th><th>Restricted</th></tr>
<table class="bordered"><tr class="header"><th>Name</th><th>Description</th><th>Restricted</th></tr>
take one string as argument and return a wordlist, i.e. a list of strings. The wordlist
<p>There are no built-in list-valued functions. <code class="module"><a href="/mod/mod_ssl.html">mod_ssl</a></code>
<If "%{HTTP_HOST} == 'example.com'">
Redirect permanent / http://www.example.com
<table class="bordered"><tr class="header"><th>Name</th><th>Alternative</th> <th>Description</th></tr>
deprecated <code class="directive"><a href="/mod/mod_ssl.html#sslrequire">SSLRequire</a></code> directive.
The differences are described in <code class="directive"><a href="/mod/mod_ssl.html#sslrequire">SSLRequire</a></code>'s documentation.</p>
</div><div class="top"><a href="#page-header"><img src="/images/up.gif" alt="top" /></a></div><div class="section"><h2><a id="comments_section" name="comments_section">Comments</a></h2><div class="warning"><strong>Notice:</strong><br />This is not a Q&A section. Comments placed here should be pointed towards suggestions on improving the documentation or server, and may be removed again by our moderators if they are either implemented or considered invalid/off-topic. Questions on how to manage the Apache HTTP Server should be directed at either our IRC channel, #httpd, on Freenode, or sent to our <a href="http://httpd.apache.org/lists.html">mailing lists</a>.</div>
var comments_identifier = 'http://httpd.apache.org/docs/trunk/expr.html';
if (w.location.hostname.toLowerCase() == "httpd.apache.org") {
d.write('<div id="comments_thread"><\/div>');
var s = d.createElement('script');
s.type = 'text/javascript';
s.async = true;
s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier;
(d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s);
d.write('<div id="comments_thread">Comments are disabled for this page at the moment.<\/div>');
<p class="apache">Copyright 2012 The Apache Software Foundation.<br />Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.</p>
<p class="menu"><a href="/mod/">Modules</a> | <a href="/mod/directives.html">Directives</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="/glossary.html">Glossary</a> | <a href="/sitemap.html">Sitemap</a></p></div><script type="text/javascript"><!--//--><![CDATA[//><!--