1 <?xml version="1.0" encoding="ISO-8859-1"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>
4 <meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type" />
6 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
7 This file is generated from xml source: DO NOT EDIT
8 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
10 <title>Expressions in Apache HTTP Server - Apache HTTP Server Version 2.5</title>
11 <link href="./style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
12 <link href="./style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
13 <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" />
14 <script src="./style/scripts/prettify.min.js" type="text/javascript">
17 <link href="./images/favicon.ico" rel="shortcut icon" /></head>
18 <body id="manual-page"><div id="page-header">
19 <p class="menu"><a href="./mod/">Modules</a> | <a href="./mod/quickreference.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>
20 <p class="apache">Apache HTTP Server Version 2.5</p>
21 <img alt="" src="./images/feather.png" /></div>
22 <div class="up"><a href="./"><img title="<-" alt="<-" src="./images/left.gif" /></a></div>
24 <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>
26 <p><span>Available Languages: </span><a href="./en/expr.html" title="English"> en </a> |
27 <a href="./fr/expr.html" hreflang="fr" rel="alternate" title="Français"> fr </a></p>
30 <p>Historically, there are several syntax variants for expressions
31 used to express a condition in the different modules of the Apache
32 HTTP Server. There is some ongoing effort to only use a single
33 variant, called <em>ap_expr</em>, for all configuration directives.
34 This document describes the <em>ap_expr</em> expression parser.
36 <p>The <em>ap_expr</em> expression is intended to replace most other
37 expression variants in HTTPD. For example, the deprecated <code class="directive"><a href="./mod/mod_ssl.html#sslrequire">SSLRequire</a></code> expressions can be replaced
38 by <a href="mod/mod_authz_core.html#reqexpr">Require expr</a>. </p>
40 <div id="quickview"><ul id="toc"><li><img alt="" src="./images/down.gif" /> <a href="#grammar">Grammar in Backus-Naur Form notation</a></li>
41 <li><img alt="" src="./images/down.gif" /> <a href="#vars">Variables</a></li>
42 <li><img alt="" src="./images/down.gif" /> <a href="#binop">Binary operators</a></li>
43 <li><img alt="" src="./images/down.gif" /> <a href="#unnop">Unary operators</a></li>
44 <li><img alt="" src="./images/down.gif" /> <a href="#functions">Functions</a></li>
45 <li><img alt="" src="./images/down.gif" /> <a href="#examples">Example expressions</a></li>
46 <li><img alt="" src="./images/down.gif" /> <a href="#other">Other</a></li>
47 <li><img alt="" src="./images/down.gif" /> <a href="#sslrequire">Comparison with SSLRequire</a></li>
48 <li><img alt="" src="./images/down.gif" /> <a href="#compatibility">Version History</a></li>
49 </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/core.html#errordocument">ErrorDocument</a></code></li><li><code class="directive"><a href="./mod/mod_alias.html#alias">Alias</a></code></li><li><code class="directive"><a href="./mod/mod_alias.html#scriptalias">ScriptAlias</a></code></li><li><code class="directive"><a href="./mod/mod_alias.html#redirect">Redirect</a></code></li><li><code class="directive"><a href="./mod/mod_auth_basic.html#authbasicfake">AuthBasicFake</a></code></li><li><code class="directive"><a href="./mod/mod_auth_form.html#authformloginrequiredlocation">AuthFormLoginRequiredLocation</a></code></li><li><code class="directive"><a href="./mod/mod_auth_form.html#authformloginsuccesslocation">AuthFormLoginSuccessLocation</a></code></li><li><code class="directive"><a href="./mod/mod_auth_form.html#authformlogoutlocation">AuthFormLogoutLocation</a></code></li><li><code class="directive"><a href="./mod/mod_authn_core.html#authname">AuthName</a></code></li><li><code class="directive"><a href="./mod/mod_authn_core.html#authtype">AuthType</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><code class="directive"><a href="./mod/mod_crypto.html#cryptokey">CryptoKey</a></code></li><li><code class="directive"><a href="./mod/mod_crypto.html#cryptoiv">CryptoIV</a></code></li><li><a href="mod/mod_authz_core.html#reqexpr">Require expr</a></li><li><a href="mod/mod_authnz_ldap.html#requser">Require ldap-user</a></li><li><a href="mod/mod_authnz_ldap.html#reqgroup">Require ldap-group</a></li><li><a href="mod/mod_authnz_ldap.html#reqdn">Require ldap-dn</a></li><li><a href="mod/mod_authnz_ldap.html#reqattribute">Require ldap-attribute</a></li><li><a href="mod/mod_authnz_ldap.html#reqfilter">Require ldap-filter</a></li><li><a href="mod/mod_authnz_ldap.html#reqsearch">Require ldap-search</a></li><li><a href="mod/mod_authz_dbd.html#reqgroup">Require dbd-group</a></li><li><a href="mod/mod_authz_dbm.html#reqgroup">Require dbm-group</a></li><li><a href="mod/mod_authz_groupfile.html#reqgroup">Require group</a></li><li><a href="mod/mod_authz_host.html#reqhost">Require host</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><li><a href="#comments_section">Comments</a></li></ul></div>
50 <div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
52 <h2><a name="grammar" id="grammar">Grammar in Backus-Naur Form notation</a></h2>
54 <p><a href="http://en.wikipedia.org/wiki/Backus%E2%80%93Naur_Form">Backus-Naur
55 Form</a> (BNF) is a notation technique for context-free grammars,
56 often used to describe the syntax of languages used in computing.
57 In most cases, expressions are used to express boolean values.
58 For these, the starting point in the BNF is <code>expr</code>.
59 However, a few directives like <code class="directive"><a href="./mod/mod_log_debug.html#logmessage">LogMessage</a></code> accept expressions
60 that evaluate to a string value. For those, the starting point in
61 the BNF is <code>string</code>.
64 <pre>expr ::= "<strong>true</strong>" | "<strong>false</strong>"
65 | "<strong>!</strong>" expr
66 | expr "<strong>&&</strong>" expr
67 | expr "<strong>||</strong>" expr
68 | "<strong>(</strong>" expr "<strong>)</strong>"
75 | word "<strong>in</strong>" "<strong>{</strong>" wordlist "<strong>}</strong>"
76 | word "<strong>in</strong>" listfunction
77 | word "<strong>=~</strong>" regex
78 | word "<strong>!~</strong>" regex
81 stringcomp ::= word "<strong>==</strong>" word
82 | word "<strong>!=</strong>" word
83 | word "<strong><</strong>" word
84 | word "<strong><=</strong>" word
85 | word "<strong>></strong>" word
86 | word "<strong>>=</strong>" word
88 integercomp ::= word "<strong>-eq</strong>" word | word "<strong>eq</strong>" word
89 | word "<strong>-ne</strong>" word | word "<strong>ne</strong>" word
90 | word "<strong>-lt</strong>" word | word "<strong>lt</strong>" word
91 | word "<strong>-le</strong>" word | word "<strong>le</strong>" word
92 | word "<strong>-gt</strong>" word | word "<strong>gt</strong>" word
93 | word "<strong>-ge</strong>" word | word "<strong>ge</strong>" word
96 | wordlist "<strong>,</strong>" word
98 word ::= word "<strong>.</strong>" word
100 | "<strong>'</strong>" string "<strong>'</strong>"
101 | "<strong>"</strong>" string "<strong>"</strong>"
106 string ::= stringpart
109 stringpart ::= cstring
116 variable ::= "<strong>%{</strong>" varname "<strong>}</strong>"
117 | "<strong>%{</strong>" funcname "<strong>:</strong>" funcargs "<strong>}</strong>"
119 rebackref ::= "<strong>$</strong>" [0-9]
121 function ::= funcname "<strong>(</strong>" wordlist "<strong>)</strong>"
123 listfunction ::= listfuncname "<strong>(</strong>" word "<strong>)</strong>"</pre>
126 </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
127 <div class="section">
128 <h2><a name="vars" id="vars">Variables</a></h2>
131 <p>The expression parser provides a number of variables of the form
132 <code>%{HTTP_HOST}</code>. Note that the value of a variable may depend
133 on the phase of the request processing in which it is evaluated. For
134 example, an expression used in an <code class="directive"><If ></code>
135 directive is evaluated before authentication is done. Therefore,
136 <code>%{REMOTE_USER}</code> will not be set in this case.</p>
138 <p>The following variables provide the values of the named HTTP request
139 headers. The values of other headers can be obtained with the
140 <code>req</code> <a href="#functions">function</a>. Using these
141 variables may cause the header name to be added to the Vary
142 header of the HTTP response, except where otherwise noted for the
143 directive accepting the expression. The <code>req_novary</code>
144 <a href="#functions">function</a> may be used to circumvent this
147 <table class="bordered"><tr class="header"><th>Name</th></tr>
148 <tr><td><code>HTTP_ACCEPT</code></td></tr>
149 <tr class="odd"><td><code>HTTP_COOKIE</code></td></tr>
150 <tr><td><code>HTTP_FORWARDED</code></td></tr>
151 <tr class="odd"><td><code>HTTP_HOST</code></td></tr>
152 <tr><td><code>HTTP_PROXY_CONNECTION</code></td></tr>
153 <tr class="odd"><td><code>HTTP_REFERER</code></td></tr>
154 <tr><td><code>HTTP_USER_AGENT</code></td></tr>
157 <p>Other request related variables</p>
159 <table class="bordered"><tr class="header"><th>Name</th><th>Description</th></tr>
160 <tr><td><code>REQUEST_METHOD</code></td>
161 <td>The HTTP method of the incoming request (e.g.
162 <code>GET</code>)</td></tr>
163 <tr class="odd"><td><code>REQUEST_SCHEME</code></td>
164 <td>The scheme part of the request's URI</td></tr>
165 <tr><td><code>REQUEST_URI</code></td>
166 <td>The path part of the request's URI</td></tr>
167 <tr class="odd"><td><code>DOCUMENT_URI</code></td>
168 <td>Same as <code>REQUEST_URI</code></td></tr>
169 <tr><td><code>REQUEST_FILENAME</code></td>
170 <td>The full local filesystem path to the file or script matching the
171 request, if this has already been determined by the server at the
172 time <code>REQUEST_FILENAME</code> is referenced. Otherwise, such
173 as when used in virtual host context, the same value as
174 <code>REQUEST_URI</code> </td></tr>
175 <tr class="odd"><td><code>SCRIPT_FILENAME</code></td>
176 <td>Same as <code>REQUEST_FILENAME</code></td></tr>
177 <tr><td><code>LAST_MODIFIED</code></td>
178 <td>The date and time of last modification of the file in the format
179 <code>20101231235959</code>, if this has already been determined by
180 the server at the time <code>LAST_MODIFIED</code> is referenced.
182 <tr class="odd"><td><code>SCRIPT_USER</code></td>
183 <td>The user name of the owner of the script.</td></tr>
184 <tr><td><code>SCRIPT_GROUP</code></td>
185 <td>The group name of the group of the script.</td></tr>
186 <tr class="odd"><td><code>PATH_INFO</code></td>
187 <td>The trailing path name information, see
188 <code class="directive"><a href="./mod/core.html#acceptpathinfo">AcceptPathInfo</a></code></td></tr>
189 <tr><td><code>QUERY_STRING</code></td>
190 <td>The query string of the current request</td></tr>
191 <tr class="odd"><td><code>IS_SUBREQ</code></td>
192 <td>"<code>true</code>" if the current request is a subrequest,
193 "<code>false</code>" otherwise</td></tr>
194 <tr><td><code>THE_REQUEST</code></td>
195 <td>The complete request line (e.g.,
196 "<code>GET /index.html HTTP/1.1</code>")</td></tr>
197 <tr class="odd"><td><code>REMOTE_ADDR</code></td>
198 <td>The IP address of the remote host</td></tr>
199 <tr><td><code>REMOTE_HOST</code></td>
200 <td>The host name of the remote host</td></tr>
201 <tr class="odd"><td><code>REMOTE_USER</code></td>
202 <td>The name of the authenticated user, if any (not available during <code class="directive"><If></code>)</td></tr>
203 <tr><td><code>REMOTE_IDENT</code></td>
204 <td>The user name set by <code class="module"><a href="./mod/mod_ident.html">mod_ident</a></code></td></tr>
205 <tr class="odd"><td><code>SERVER_NAME</code></td>
206 <td>The <code class="directive"><a href="./mod/core.html#servername">ServerName</a></code> of
207 the current vhost</td></tr>
208 <tr><td><code>SERVER_PORT</code></td>
209 <td>The server port of the current vhost, see
210 <code class="directive"><a href="./mod/core.html#servername">ServerName</a></code></td></tr>
211 <tr class="odd"><td><code>SERVER_ADMIN</code></td>
212 <td>The <code class="directive"><a href="./mod/core.html#serveradmin">ServerAdmin</a></code> of
213 the current vhost</td></tr>
214 <tr><td><code>SERVER_PROTOCOL</code></td>
215 <td>The protocol used by the request (e.g. HTTP/1.1). In some types of
216 internal subrequests, this variable has the value
217 <code>INCLUDED</code>.</td></tr>
218 <tr class="odd"><td><code>SERVER_PROTOCOL_VERSION</code></td>
219 <td>A number that encodes the HTTP version of the request:
220 <code>1000 * major + minor</code>. For example, <code>1001</code>
221 corresponds to HTTP/1.1 and <code>9</code> corresponds
222 to HTTP/0.9</td></tr>
223 <tr><td><code>SERVER_PROTOCOL_VERSION_MAJOR</code></td>
224 <td>The major version part of the HTTP version of the request,
225 e.g. <code>1</code> for HTTP/1.0</td></tr>
226 <tr class="odd"><td><code>SERVER_PROTOCOL_VERSION_MINOR</code></td>
227 <td>The minor version part of the HTTP version of the request,
228 e.g. <code>0</code> for HTTP/1.0</td></tr>
229 <tr><td><code>DOCUMENT_ROOT</code></td>
230 <td>The <code class="directive"><a href="./mod/core.html#documentroot">DocumentRoot</a></code> of
231 the current vhost</td></tr>
232 <tr class="odd"><td><code>AUTH_TYPE</code></td>
233 <td>The configured <code class="directive"><a href="./mod/mod_authn_core.html#authtype">AuthType</a></code> (e.g.
234 "<code>basic</code>")</td></tr>
235 <tr><td><code>CONTENT_TYPE</code></td>
236 <td>The content type of the response (not available during <code class="directive"><If></code>)</td></tr>
237 <tr class="odd"><td><code>HANDLER</code></td>
238 <td>The name of the <a href="handler.html">handler</a> creating
239 the response</td></tr>
240 <tr><td><code>HTTP2</code></td>
241 <td>"<code>on</code>" if the request uses http/2,
242 "<code>off</code>" otherwise</td></tr>
243 <tr class="odd"><td><code>HTTPS</code></td>
244 <td>"<code>on</code>" if the request uses https,
245 "<code>off</code>" otherwise</td></tr>
246 <tr><td><code>IPV6</code></td>
247 <td>"<code>on</code>" if the connection uses IPv6,
248 "<code>off</code>" otherwise</td></tr>
249 <tr class="odd"><td><code>REQUEST_STATUS</code></td>
250 <td>The HTTP error status of the request (not available during <code class="directive"><If></code>)</td></tr>
251 <tr><td><code>REQUEST_LOG_ID</code></td>
252 <td>The error log id of the request (see
253 <code class="directive"><a href="./mod/core.html#errorlogformat">ErrorLogFormat</a></code>)</td></tr>
254 <tr class="odd"><td><code>CONN_LOG_ID</code></td>
255 <td>The error log id of the connection (see
256 <code class="directive"><a href="./mod/core.html#errorlogformat">ErrorLogFormat</a></code>)</td></tr>
257 <tr><td><code>CONN_REMOTE_ADDR</code></td>
258 <td>The peer IP address of the connection (see the
259 <code class="module"><a href="./mod/mod_remoteip.html">mod_remoteip</a></code> module)</td></tr>
260 <tr class="odd"><td><code>CONTEXT_PREFIX</code></td>
262 <tr><td><code>CONTEXT_DOCUMENT_ROOT</code></td>
266 <p>Misc variables</p>
268 <table class="bordered"><tr class="header"><th>Name</th><th>Description</th></tr>
269 <tr><td><code>TIME_YEAR</code></td>
270 <td>The current year (e.g. <code>2010</code>)</td></tr>
271 <tr class="odd"><td><code>TIME_MON</code></td>
272 <td>The current month (<code>01</code>, ..., <code>12</code>)</td></tr>
273 <tr><td><code>TIME_DAY</code></td>
274 <td>The current day of the month (<code>01</code>, ...)</td></tr>
275 <tr class="odd"><td><code>TIME_HOUR</code></td>
276 <td>The hour part of the current time
277 (<code>00</code>, ..., <code>23</code>)</td></tr>
278 <tr><td><code>TIME_MIN</code></td>
279 <td>The minute part of the current time </td></tr>
280 <tr class="odd"><td><code>TIME_SEC</code></td>
281 <td>The second part of the current time </td></tr>
282 <tr><td><code>TIME_WDAY</code></td>
283 <td>The day of the week (starting with <code>0</code>
284 for Sunday)</td></tr>
285 <tr class="odd"><td><code>TIME</code></td>
286 <td>The date and time in the format
287 <code>20101231235959</code></td></tr>
288 <tr><td><code>SERVER_SOFTWARE</code></td>
289 <td>The server version string</td></tr>
290 <tr class="odd"><td><code>API_VERSION</code></td>
291 <td>The date of the API version (module magic number)</td></tr>
294 <p>Some modules register additional variables, see e.g.
295 <code class="module"><a href="./mod/mod_ssl.html">mod_ssl</a></code>.</p>
297 </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
298 <div class="section">
299 <h2><a name="binop" id="binop">Binary operators</a></h2>
302 <p>With the exception of some built-in comparison operators, binary
303 operators have the form "<code>-[a-zA-Z][a-zA-Z0-9_]+</code>", i.e. a
304 minus and at least two characters. The name is not case sensitive.
305 Modules may register additional binary operators.</p>
307 <h3><a name="comp" id="comp">Comparison operators</a></h3>
310 <table class="bordered"><tr class="header"><th>Name</th><th>Alternative</th> <th>Description</th></tr>
311 <tr><td><code>==</code></td>
312 <td><code>=</code></td>
313 <td>String equality</td></tr>
314 <tr class="odd"><td><code>!=</code></td>
316 <td>String inequality</td></tr>
317 <tr><td><code><</code></td>
319 <td>String less than</td></tr>
320 <tr class="odd"><td><code><=</code></td>
322 <td>String less than or equal</td></tr>
323 <tr><td><code>></code></td>
325 <td>String greater than</td></tr>
326 <tr class="odd"><td><code>>=</code></td>
328 <td>String greater than or equal</td></tr>
329 <tr><td><code>=~</code></td>
331 <td>String matches the regular expression</td></tr>
332 <tr class="odd"><td><code>!~</code></td>
334 <td>String does not match the regular expression</td></tr>
335 <tr><td><code>-eq</code></td>
336 <td><code>eq</code></td>
337 <td>Integer equality</td></tr>
338 <tr class="odd"><td><code>-ne</code></td>
339 <td><code>ne</code></td>
340 <td>Integer inequality</td></tr>
341 <tr><td><code>-lt</code></td>
342 <td><code>lt</code></td>
343 <td>Integer less than</td></tr>
344 <tr class="odd"><td><code>-le</code></td>
345 <td><code>le</code></td>
346 <td>Integer less than or equal</td></tr>
347 <tr><td><code>-gt</code></td>
348 <td><code>gt</code></td>
349 <td>Integer greater than</td></tr>
350 <tr class="odd"><td><code>-ge</code></td>
351 <td><code>ge</code></td>
352 <td>Integer greater than or equal</td></tr>
356 <h3><a name="binaryother" id="binaryother">Other binary operators</a></h3>
359 <table class="bordered"><tr class="header"><th>Name</th><th>Description</th></tr>
360 <tr><td><code>-ipmatch</code></td>
361 <td>IP address matches address/netmask</td></tr>
362 <tr class="odd"><td><code>-strmatch</code></td>
363 <td>left string matches pattern given by right string (containing
364 wildcards *, ?, [])</td></tr>
365 <tr><td><code>-strcmatch</code></td>
366 <td>same as <code>-strmatch</code>, but case insensitive</td></tr>
367 <tr class="odd"><td><code>-fnmatch</code></td>
368 <td>same as <code>-strmatch</code>, but slashes are not matched by
373 </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
374 <div class="section">
375 <h2><a name="unnop" id="unnop">Unary operators</a></h2>
378 <p>Unary operators take one argument and have the form
379 "<code>-[a-zA-Z]</code>", i.e. a minus and one character.
380 The name <em>is</em> case sensitive.
381 Modules may register additional unary operators.</p>
383 <table class="bordered"><tr class="header"><th>Name</th><th>Description</th><th>Restricted</th></tr>
384 <tr><td><code>-d</code></td>
385 <td>The argument is treated as a filename.
386 True if the file exists and is a directory</td><td>yes</td></tr>
387 <tr class="odd"><td><code>-e</code></td>
388 <td>The argument is treated as a filename.
389 True if the file (or dir or special) exists</td><td>yes</td></tr>
390 <tr><td><code>-f</code></td>
391 <td>The argument is treated as a filename.
392 True if the file exists and is regular file</td><td>yes</td></tr>
393 <tr class="odd"><td><code>-s</code></td>
394 <td>The argument is treated as a filename.
395 True if the file exists and is not empty</td><td>yes</td></tr>
396 <tr><td><code>-L</code></td>
397 <td>The argument is treated as a filename.
398 True if the file exists and is symlink</td><td>yes</td></tr>
399 <tr class="odd"><td><code>-h</code></td>
400 <td>The argument is treated as a filename.
401 True if the file exists and is symlink
402 (same as <code>-L</code>)</td><td>yes</td></tr>
403 <tr><td><code>-F</code></td>
404 <td>True if string is a valid file, accessible via all the server's
405 currently-configured access controls for that path. This uses an
406 internal subrequest to do the check, so use it with care - it can
407 impact your server's performance!</td><td /></tr>
408 <tr class="odd"><td><code>-U</code></td>
409 <td>True if string is a valid URL, accessible via all the server's
410 currently-configured access controls for that path. This uses an
411 internal subrequest to do the check, so use it with care - it can
412 impact your server's performance!</td><td /></tr>
413 <tr><td><code>-A</code></td>
414 <td>Alias for <code>-U</code></td><td /></tr>
415 <tr class="odd"><td><code>-n</code></td>
416 <td>True if string is not empty</td><td /></tr>
417 <tr><td><code>-z</code></td>
418 <td>True if string is empty</td><td /></tr>
419 <tr class="odd"><td><code>-T</code></td>
420 <td>False if string is empty, "<code>0</code>", "<code>off</code>",
421 "<code>false</code>", or "<code>no</code>" (case insensitive).
422 True otherwise.</td><td /></tr>
423 <tr><td><code>-R</code></td>
424 <td>Same as "<code>%{REMOTE_ADDR} -ipmatch ...</code>", but more
429 <p>The operators marked as "restricted" are not available in some modules
430 like <code class="module"><a href="./mod/mod_include.html">mod_include</a></code>.</p>
431 </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
432 <div class="section">
433 <h2><a name="functions" id="functions">Functions</a></h2>
436 <p>Normal string-valued functions take one string as argument and return
437 a string. Functions names are not case sensitive.
438 Modules may register additional functions.</p>
440 <table class="bordered"><tr class="header"><th>Name</th><th>Description</th><th>Special notes</th></tr>
441 <tr><td><code>req</code>, <code>http</code></td>
442 <td>Get HTTP request header; header names may be added to the Vary
443 header, see below</td><td /></tr>
444 <tr class="odd"><td><code>req_novary</code></td>
445 <td>Same as <code>req</code>, but header names will not be added to the
446 Vary header</td><td /></tr>
447 <tr><td><code>resp</code></td>
448 <td>Get HTTP response header (most response headers will not yet be set
449 during <code class="directive"><If></code>)</td><td /></tr>
450 <tr class="odd"><td><code>reqenv</code></td>
451 <td>Lookup request environment variable (as a shortcut,
452 <code>v</code> can also be used to access variables).
454 <td>ordering</td></tr>
455 <tr><td><code>osenv</code></td>
456 <td>Lookup operating system environment variable</td><td /></tr>
457 <tr class="odd"><td><code>note</code></td>
458 <td>Lookup request note</td><td>ordering</td></tr>
459 <tr><td><code>env</code></td>
460 <td>Return first match of <code>note</code>, <code>reqenv</code>,
461 <code>osenv</code></td><td>ordering</td></tr>
462 <tr class="odd"><td><code>tolower</code></td>
463 <td>Convert string to lower case</td><td /></tr>
464 <tr><td><code>toupper</code></td>
465 <td>Convert string to upper case</td><td /></tr>
466 <tr class="odd"><td><code>escape</code></td>
467 <td>Escape special characters in %hex encoding</td><td /></tr>
468 <tr><td><code>unescape</code></td>
469 <td>Unescape %hex encoded string, leaving encoded slashes alone;
470 return empty string if %00 is found</td><td /></tr>
471 <tr class="odd"><td><code>base64</code></td>
472 <td>Encode the string using base64 encoding</td><td /></tr>
473 <tr><td><code>unbase64</code></td>
474 <td>Decode base64 encoded string, return truncated string if 0x00 is
475 found</td><td /></tr>
476 <tr class="odd"><td><code>md5</code></td>
477 <td>Hash the string using MD5, then encode the hash with hexadecimal
478 encoding</td><td /></tr>
479 <tr><td><code>sha1</code></td>
480 <td>Hash the string using SHA1, then encode the hash with hexadecimal
481 encoding</td><td /></tr>
482 <tr class="odd"><td><code>file</code></td>
483 <td>Read contents from a file (including line endings, when present)
484 </td><td>restricted</td></tr>
485 <tr><td><code>filemod</code></td>
486 <td>Return last modification time of a file (or 0 if file does not exist
487 or is not regular file)</td><td>restricted</td></tr>
488 <tr class="odd"><td><code>filesize</code></td>
489 <td>Return size of a file (or 0 if file does not exist or is not
490 regular file)</td><td>restricted</td></tr>
491 <tr><td><code>ldap</code></td>
492 <td>Escape characters as required by LDAP distinguished name escaping
493 (RFC4514) and LDAP filter escaping (RFC4515).</td><td /></tr>
494 <tr class="odd"><td><code>replace</code></td>
495 <td>replace(string, "from", "to") replaces all occurences of "from"
496 in the string with "to".</td><td /></tr>
499 <p>The functions marked as "restricted" in the final column are not
500 available in some modules like <code class="module"><a href="./mod/mod_include.html">mod_include</a></code>.</p>
502 <p>The functions marked as "ordering" in the final column require some
503 consideration for the ordering of different components of the server,
504 especially when the function is used within the
505 <<code class="directive"><a href="./mod/core.html#if">If</a></code>> directive which is
506 evaluated relatively early.</p>
508 <h3>Environment variable ordering</h3>
509 When environment variables are looked up within an
510 <<code class="directive"><a href="./mod/core.html#if">If</a></code>> condition, it's important
511 to consider how extremely early in request processing that this
512 resolution occurs. As a guideline, any directive defined outside of virtual host
513 context (directory, location, htaccess) is not likely to have yet had a
514 chance to execute. <code class="directive"><a href="./mod/mod_setenvif.html#setenvif">SetEnvIf</a></code>
515 in virtual host scope is one directive that runs prior to this resolution
518 When <code>reqenv</code> is used outside of <<code class="directive"><a href="./mod/core.html#if">If</a></code>>, the resolution will generally occur later, but the
519 exact timing depends on the directive the expression has been used within.
522 <p>When the functions <code>req</code> or <code>http</code> are used,
523 the header name will automatically be added to the Vary header of the
524 HTTP response, except where otherwise noted for the directive accepting
525 the expression. The <code>req_novary</code> function can be used to
526 prevent names from being added to the Vary header.</p>
528 <p>In addition to string-valued functions, there are also
529 list-valued functions which take one string as argument and return a
530 wordlist, i.e. a list of strings. The wordlist can be used with the
531 special <code>-in</code> operator. Functions names are not case
532 sensitive. Modules may register additional functions.</p>
534 <p>There are no built-in list-valued functions. <code class="module"><a href="./mod/mod_ssl.html">mod_ssl</a></code>
535 provides <code>PeerExtList</code>. See the description of
536 <code class="directive"><a href="./mod/mod_ssl.html#sslrequire">SSLRequire</a></code> for details
537 (but <code>PeerExtList</code> is also usable outside
538 of <code class="directive"><a href="./mod/mod_ssl.html#sslrequire">SSLRequire</a></code>).</p>
540 </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
541 <div class="section">
542 <h2><a name="examples" id="examples">Example expressions</a></h2>
545 <p>The following examples show how expressions might be used to
546 evaluate requests:</p>
549 <pre class="prettyprint lang-config"># Compare the host name to example.com and redirect to www.example.com if it matches
550 <If "%{HTTP_HOST} == 'example.com'">
551 Redirect permanent "/" "http://www.example.com/"
554 # Force text/plain if requesting a file with the query string contains 'forcetext'
555 <If "%{QUERY_STRING} =~ /forcetext/">
559 # Only allow access to this content during business hours
560 <Directory "/foo/bar/business">
561 Require expr %{TIME_HOUR} -gt 9 && %{TIME_HOUR} -lt 17
564 # Check a HTTP header for a list of values
565 <If "%{HTTP:X-example-header} in { 'foo', 'bar', 'baz' }">
566 Header set matched true
569 # Check an environment variable for a regular expression, negated.
570 <If "! reqenv('REDIRECT_FOO') =~ /bar/">
571 Header set matched true
574 # Check result of URI mapping by running in Directory context with -f
575 <Directory "/var/www">
576 AddEncoding x-gzip gz
577 <If "-f '%{REQUEST_FILENAME}.unzipme' && ! %{HTTP:Accept-Encoding} =~ /gzip/">
578 SetOutputFilter INFLATE
582 # Check against the client IP
583 <If "-R '192.168.1.0/24'">
584 Header set matched true
587 # Function examples in boolean context
588 <If "md5('foo') == 'acbd18db4cc2f85cedef654fccc4a4d8'">
589 Header set checksum-matched true
591 <If "md5('foo') == replace('md5:XXXd18db4cc2f85cedef654fccc4a4d8', 'md5:XXX', 'acb')">
592 Header set checksum-matched-2 true
595 # Function example in string context
596 Header set foo-checksum "expr=%{md5:foo}"
598 # This delays the evaluation of the condition clause compared to <If>
599 Header always set CustomHeader my-value "expr=%{REQUEST_URI} =~ m#^/special_path\.php$#"</pre>
601 </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
602 <div class="section">
603 <h2><a name="other" id="other">Other</a></h2>
606 <table class="bordered"><tr class="header"><th>Name</th><th>Alternative</th> <th>Description</th></tr>
607 <tr><td><code>-in</code></td>
608 <td><code>in</code></td>
609 <td>string contained in wordlist</td></tr>
610 <tr class="odd"><td><code>/regexp/</code></td>
611 <td><code>m#regexp#</code></td>
612 <td>Regular expression (the second form allows different
613 delimiters than /)</td></tr>
614 <tr><td><code>/regexp/i</code></td>
615 <td><code>m#regexp#i</code></td>
616 <td>Case insensitive regular expression</td></tr>
617 <tr class="odd"><td><code>$0 ... $9</code></td>
619 <td>Regular expression backreferences</td></tr>
622 <h3><a name="rebackref" id="rebackref">Regular expression backreferences</a></h3>
624 <p>The strings <code>$0</code> ... <code>$9</code> allow to reference
625 the capture groups from a previously executed, successfully
626 matching regular expressions. They can normally only be used in the
627 same expression as the matching regex, but some modules allow special
631 </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
632 <div class="section">
633 <h2><a name="sslrequire" id="sslrequire">Comparison with SSLRequire</a></h2>
635 <p>The <em>ap_expr</em> syntax is mostly a superset of the syntax of the
636 deprecated <code class="directive"><a href="./mod/mod_ssl.html#sslrequire">SSLRequire</a></code> directive.
637 The differences are described in <code class="directive"><a href="./mod/mod_ssl.html#sslrequire">SSLRequire</a></code>'s documentation.</p>
638 </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
639 <div class="section">
640 <h2><a name="compatibility" id="compatibility">Version History</a></h2>
642 <p>The <code>req_novary</code> <a href="#functions">function</a>
643 is available for versions 2.4.4 and later.</p>
644 <p>The <code>SERVER_PROTOCOL_VERSION</code>,
645 <code>SERVER_PROTOCOL_VERSION_MAJOR</code> and
646 <code>SERVER_PROTOCOL_VERSION_MINOR</code>
647 <a href="#vars">variables</a>
648 are available for versions 2.5.0 and later.</p>
650 <div class="bottomlang">
651 <p><span>Available Languages: </span><a href="./en/expr.html" title="English"> en </a> |
652 <a href="./fr/expr.html" hreflang="fr" rel="alternate" title="Français"> fr </a></p>
653 </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>
654 <script type="text/javascript"><!--//--><![CDATA[//><!--
655 var comments_shortname = 'httpd';
656 var comments_identifier = 'http://httpd.apache.org/docs/trunk/expr.html';
658 if (w.location.hostname.toLowerCase() == "httpd.apache.org") {
659 d.write('<div id="comments_thread"><\/div>');
660 var s = d.createElement('script');
661 s.type = 'text/javascript';
663 s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier;
664 (d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s);
667 d.write('<div id="comments_thread">Comments are disabled for this page at the moment.<\/div>');
669 })(window, document);
670 //--><!]]></script></div><div id="footer">
671 <p class="apache">Copyright 2016 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>
672 <p class="menu"><a href="./mod/">Modules</a> | <a href="./mod/quickreference.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[//><!--
673 if (typeof(prettyPrint) !== 'undefined') {