]> granicus.if.org Git - apache/blob - docs/manual/expr.xml
Documentation rebuild
[apache] / docs / manual / expr.xml
1 <?xml version="1.0" encoding="UTF-8" ?>
2 <!DOCTYPE manualpage SYSTEM "./style/manualpage.dtd">
3 <?xml-stylesheet type="text/xsl" href="./style/manual.en.xsl"?>
4 <!-- $LastChangedRevision$ -->
5
6 <!--
7  Licensed to the Apache Software Foundation (ASF) under one or more
8  contributor license agreements.  See the NOTICE file distributed with
9  this work for additional information regarding copyright ownership.
10  The ASF licenses this file to You under the Apache License, Version 2.0
11  (the "License"); you may not use this file except in compliance with
12  the License.  You may obtain a copy of the License at
13
14      http://www.apache.org/licenses/LICENSE-2.0
15
16  Unless required by applicable law or agreed to in writing, software
17  distributed under the License is distributed on an "AS IS" BASIS,
18  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  See the License for the specific language governing permissions and
20  limitations under the License.
21 -->
22
23 <manualpage metafile="expr.xml.meta">
24
25   <title>Expressions in Apache HTTP Server</title>
26
27   <summary>
28     <p>Historically, there are several syntax variants for expressions
29     used to express a condition in the different modules of the Apache
30     HTTP Server.  There is some ongoing effort to only use a single
31     variant, called <em>ap_expr</em>, for all configuration directives.
32     This document describes the <em>ap_expr</em> expression parser.
33     </p>
34     <p>The <em>ap_expr</em> expression is intended to replace most other
35     expression variants in HTTPD. For example, the deprecated <directive
36     module="mod_ssl">SSLRequire</directive> expressions can be replaced
37     by <a href="mod/mod_authz_core.html#reqexpr">Require expr</a>.  </p>
38   </summary>
39
40 <seealso><directive module="core" type="section">If</directive></seealso>
41 <seealso><directive module="core" type="section">ElseIf</directive></seealso>
42 <seealso><directive module="core" type="section">Else</directive></seealso>
43 <seealso><directive module="core">ErrorDocument</directive></seealso>
44 <seealso><directive module="mod_alias">Alias</directive></seealso>
45 <seealso><directive module="mod_alias">ScriptAlias</directive></seealso>
46 <seealso><directive module="mod_alias">Redirect</directive></seealso>
47 <seealso><directive module="mod_auth_basic">AuthBasicFake</directive></seealso>
48 <seealso><directive module="mod_auth_form">AuthFormLoginRequiredLocation</directive></seealso>
49 <seealso><directive module="mod_auth_form">AuthFormLoginSuccessLocation</directive></seealso>
50 <seealso><directive module="mod_auth_form">AuthFormLogoutLocation</directive></seealso>
51 <seealso><directive module="mod_authn_core">AuthName</directive></seealso>
52 <seealso><directive module="mod_authn_core">AuthType</directive></seealso>
53 <seealso><directive module="mod_rewrite">RewriteCond</directive></seealso>
54 <seealso><directive module="mod_setenvif">SetEnvIfExpr</directive></seealso>
55 <seealso><directive module="mod_headers">Header</directive></seealso>
56 <seealso><directive module="mod_headers">RequestHeader</directive></seealso>
57 <seealso><directive module="mod_filter">FilterProvider</directive></seealso>
58 <seealso><directive module="mod_crypto">CryptoKey</directive></seealso>
59 <seealso><directive module="mod_crypto">CryptoIV</directive></seealso>
60 <seealso><a href="mod/mod_authz_core.html#reqexpr">Require expr</a></seealso>
61 <seealso><a href="mod/mod_authnz_ldap.html#requser">Require ldap-user</a></seealso>
62 <seealso><a href="mod/mod_authnz_ldap.html#reqgroup">Require ldap-group</a></seealso>
63 <seealso><a href="mod/mod_authnz_ldap.html#reqdn">Require ldap-dn</a></seealso>
64 <seealso><a href="mod/mod_authnz_ldap.html#reqattribute">Require ldap-attribute</a></seealso>
65 <seealso><a href="mod/mod_authnz_ldap.html#reqfilter">Require ldap-filter</a></seealso>
66 <seealso><a href="mod/mod_authnz_ldap.html#reqsearch">Require ldap-search</a></seealso>
67 <seealso><a href="mod/mod_authz_dbd.html#reqgroup">Require dbd-group</a></seealso>
68 <seealso><a href="mod/mod_authz_dbm.html#reqgroup">Require dbm-group</a></seealso>
69 <seealso><a href="mod/mod_authz_groupfile.html#reqgroup">Require group</a></seealso>
70 <seealso><a href="mod/mod_authz_host.html#reqhost">Require host</a></seealso>
71 <seealso><directive module="mod_ssl">SSLRequire</directive></seealso>
72 <seealso><directive module="mod_log_debug">LogMessage</directive></seealso>
73 <seealso><module>mod_include</module></seealso>
74
75   <section id="grammar">
76     <title>Grammar in Backus-Naur Form notation</title>
77       <p><a
78       href="http://en.wikipedia.org/wiki/Backus%E2%80%93Naur_Form">Backus-Naur
79       Form</a> (BNF) is a notation technique for context-free grammars,
80       often used to describe the syntax of languages used in computing.
81       In most cases, expressions are used to express boolean values.
82       For these, the starting point in the BNF is <code>expr</code>.
83       However, a few directives like <directive
84       module="mod_log_debug">LogMessage</directive> accept expressions
85       that evaluate to a string value. For those, the starting point in
86       the BNF is <code>string</code>.
87       </p>
88 <blockquote>
89 <pre>
90 expr        ::= "<strong>true</strong>" | "<strong>false</strong>"
91               | "<strong>!</strong>" expr
92               | expr "<strong>&amp;&amp;</strong>" expr
93               | expr "<strong>||</strong>" expr
94               | "<strong>(</strong>" expr "<strong>)</strong>"
95               | comp
96
97 comp        ::= stringcomp
98               | integercomp
99               | unaryop word
100               | word binaryop word
101               | word "<strong>in</strong>" "<strong>{</strong>" wordlist "<strong>}</strong>"
102               | word "<strong>in</strong>" listfunction
103               | word "<strong>=~</strong>" regex
104               | word "<strong>!~</strong>" regex
105
106
107 stringcomp  ::= word "<strong>==</strong>" word
108               | word "<strong>!=</strong>" word
109               | word "<strong>&lt;</strong>"  word
110               | word "<strong>&lt;=</strong>" word
111               | word "<strong>&gt;</strong>"  word
112               | word "<strong>&gt;=</strong>" word
113
114 integercomp ::= word "<strong>-eq</strong>" word | word "<strong>eq</strong>" word
115               | word "<strong>-ne</strong>" word | word "<strong>ne</strong>" word
116               | word "<strong>-lt</strong>" word | word "<strong>lt</strong>" word
117               | word "<strong>-le</strong>" word | word "<strong>le</strong>" word
118               | word "<strong>-gt</strong>" word | word "<strong>gt</strong>" word
119               | word "<strong>-ge</strong>" word | word "<strong>ge</strong>" word
120
121 wordlist    ::= word
122               | wordlist "<strong>,</strong>" word
123
124 word        ::= word "<strong>.</strong>" word
125               | digit
126               | "<strong>'</strong>" string "<strong>'</strong>"
127               | "<strong>"</strong>" string "<strong>"</strong>"
128               | variable
129               | rebackref
130               | function
131
132 string      ::= stringpart
133               | string stringpart
134
135 stringpart  ::= cstring
136               | variable
137               | rebackref
138
139 cstring     ::= ...
140 digit       ::= [0-9]+
141
142 variable    ::= "<strong>%{</strong>" varname "<strong>}</strong>"
143               | "<strong>%{</strong>" funcname "<strong>:</strong>" funcargs "<strong>}</strong>"
144
145 rebackref   ::= "<strong>$</strong>" [0-9]
146
147 function     ::= funcname "<strong>(</strong>" wordlist "<strong>)</strong>"
148
149 listfunction ::= listfuncname "<strong>(</strong>" word "<strong>)</strong>"
150 </pre>
151 </blockquote>
152
153 </section>
154
155 <section id="vars">
156     <title>Variables</title>
157
158     <p>The expression parser provides a number of variables of the form
159     <code>%{HTTP_HOST}</code>. Note that the value of a variable may depend
160     on the phase of the request processing in which it is evaluated.  For
161     example, an expression used in an <directive>&lt;If &gt;</directive>
162     directive is evaluated before authentication is done. Therefore,
163     <code>%{REMOTE_USER}</code> will not be set in this case.</p>
164
165     <p>The following variables provide the values of the named HTTP request
166     headers. The values of other headers can be obtained with the
167     <code>req</code> <a href="#functions">function</a>. Using these
168     variables may cause the header name to be added to the Vary
169     header of the HTTP response, except where otherwise noted for the
170     directive accepting the expression. The <code>req_novary</code>
171     <a href="#functions">function</a> may be used to circumvent this
172     behavior.</p>
173
174     <table border="1" style="zebra">
175     <columnspec><column width="1"/></columnspec>
176
177     <tr><th>Name</th></tr>
178     <tr><td><code>HTTP_ACCEPT</code></td></tr>
179     <tr><td><code>HTTP_COOKIE</code></td></tr>
180     <tr><td><code>HTTP_FORWARDED</code></td></tr>
181     <tr><td><code>HTTP_HOST</code></td></tr>
182     <tr><td><code>HTTP_PROXY_CONNECTION</code></td></tr>
183     <tr><td><code>HTTP_REFERER</code></td></tr>
184     <tr><td><code>HTTP_USER_AGENT</code></td></tr>
185
186     </table>
187
188     <p>Other request related variables</p>
189
190     <table border="1" style="zebra">
191     <columnspec><column width=".4"/><column width=".6"/></columnspec>
192
193     <tr><th>Name</th><th>Description</th></tr>
194     <tr><td><code>REQUEST_METHOD</code></td>
195         <td>The HTTP method of the incoming request (e.g.
196             <code>GET</code>)</td></tr>
197     <tr><td><code>REQUEST_SCHEME</code></td>
198         <td>The scheme part of the request's URI</td></tr>
199     <tr><td><code>REQUEST_URI</code></td>
200         <td>The path part of the request's URI</td></tr>
201     <tr><td><code>DOCUMENT_URI</code></td>
202         <td>Same as <code>REQUEST_URI</code></td></tr>
203     <tr><td><code>REQUEST_FILENAME</code></td>
204         <td>The full local filesystem path to the file or script matching the
205             request, if this has already been determined by the server at the
206             time <code>REQUEST_FILENAME</code> is referenced. Otherwise, such
207             as when used in virtual host context, the same value as
208             <code>REQUEST_URI</code> </td></tr>
209     <tr><td><code>SCRIPT_FILENAME</code></td>
210         <td>Same as <code>REQUEST_FILENAME</code></td></tr>
211     <tr><td><code>LAST_MODIFIED</code></td>
212         <td>The date and time of last modification of the file in the format
213             <code>20101231235959</code>, if this has already been determined by
214             the server at the time <code>LAST_MODIFIED</code> is referenced.
215             </td></tr>
216     <tr><td><code>SCRIPT_USER</code></td>
217         <td>The user name of the owner of the script.</td></tr>
218     <tr><td><code>SCRIPT_GROUP</code></td>
219         <td>The group name of the group of the script.</td></tr>
220     <tr><td><code>PATH_INFO</code></td>
221         <td>The trailing path name information, see
222             <directive module="core">AcceptPathInfo</directive></td></tr>
223     <tr><td><code>QUERY_STRING</code></td>
224         <td>The query string of the current request</td></tr>
225     <tr><td><code>IS_SUBREQ</code></td>
226         <td>"<code>true</code>" if the current request is a subrequest,
227             "<code>false</code>" otherwise</td></tr>
228     <tr><td><code>THE_REQUEST</code></td>
229         <td>The complete request line (e.g.,
230             "<code>GET /index.html HTTP/1.1</code>")</td></tr>
231     <tr><td><code>REMOTE_ADDR</code></td>
232         <td>The IP address of the remote host</td></tr>
233     <tr><td><code>REMOTE_PORT</code></td>
234         <td>The port of the remote host (2.4.26 and later)</td></tr>
235     <tr><td><code>REMOTE_HOST</code></td>
236         <td>The host name of the remote host</td></tr>
237     <tr><td><code>REMOTE_USER</code></td>
238         <td>The name of the authenticated user, if any (not available during <directive>&lt;If&gt;</directive>)</td></tr>
239     <tr><td><code>REMOTE_IDENT</code></td>
240         <td>The user name set by <module>mod_ident</module></td></tr>
241     <tr><td><code>SERVER_NAME</code></td>
242         <td>The <directive module="core">ServerName</directive> of
243             the current vhost</td></tr>
244     <tr><td><code>SERVER_PORT</code></td>
245         <td>The server port of the current vhost, see
246             <directive module="core">ServerName</directive></td></tr>
247     <tr><td><code>SERVER_ADMIN</code></td>
248         <td>The <directive module="core">ServerAdmin</directive> of
249             the current vhost</td></tr>
250     <tr><td><code>SERVER_PROTOCOL</code></td>
251         <td>The protocol used by the request (e.g. HTTP/1.1). In some types of
252             internal subrequests, this variable has the value
253             <code>INCLUDED</code>.</td></tr>
254     <tr><td><code>SERVER_PROTOCOL_VERSION</code></td>
255         <td>A number that encodes the HTTP version of the request:
256             <code>1000 * major + minor</code>. For example, <code>1001</code>
257             corresponds to HTTP/1.1 and <code>9</code> corresponds
258             to HTTP/0.9</td></tr>
259     <tr><td><code>SERVER_PROTOCOL_VERSION_MAJOR</code></td>
260         <td>The major version part of the HTTP version of the request,
261             e.g. <code>1</code> for HTTP/1.0</td></tr>
262     <tr><td><code>SERVER_PROTOCOL_VERSION_MINOR</code></td>
263         <td>The minor version part of the HTTP version of the request,
264             e.g. <code>0</code> for HTTP/1.0</td></tr>
265     <tr><td><code>DOCUMENT_ROOT</code></td>
266         <td>The <directive module="core">DocumentRoot</directive> of
267             the current vhost</td></tr>
268     <tr><td><code>AUTH_TYPE</code></td>
269         <td>The configured <directive
270         module="mod_authn_core">AuthType</directive> (e.g.
271         "<code>basic</code>")</td></tr>
272     <tr><td><code>CONTENT_TYPE</code></td>
273         <td>The content type of the response (not available during <directive>&lt;If&gt;</directive>)</td></tr>
274     <tr><td><code>HANDLER</code></td>
275         <td>The name of the <a href="handler.html">handler</a> creating
276             the response</td></tr>
277     <tr><td><code>HTTP2</code></td>
278         <td>"<code>on</code>" if the request uses http/2,
279             "<code>off</code>" otherwise</td></tr>
280     <tr><td><code>HTTPS</code></td>
281         <td>"<code>on</code>" if the request uses https,
282             "<code>off</code>" otherwise</td></tr>
283     <tr><td><code>IPV6</code></td>
284         <td>"<code>on</code>" if the connection uses IPv6,
285             "<code>off</code>" otherwise</td></tr>
286     <tr><td><code>REQUEST_STATUS</code></td>
287         <td>The HTTP error status of the request (not available during <directive>&lt;If&gt;</directive>)</td></tr>
288     <tr><td><code>REQUEST_LOG_ID</code></td>
289         <td>The error log id of the request (see
290             <directive module="core">ErrorLogFormat</directive>)</td></tr>
291     <tr><td><code>CONN_LOG_ID</code></td>
292         <td>The error log id of the connection (see
293             <directive module="core">ErrorLogFormat</directive>)</td></tr>
294     <tr><td><code>CONN_REMOTE_ADDR</code></td>
295         <td>The peer IP address of the connection (see the
296             <module>mod_remoteip</module> module)</td></tr>
297     <tr><td><code>CONTEXT_PREFIX</code></td>
298         <td></td></tr>
299     <tr><td><code>CONTEXT_DOCUMENT_ROOT</code></td>
300         <td></td></tr>
301
302     </table>
303
304     <p>Misc variables</p>
305
306     <table border="1" style="zebra">
307     <columnspec><column width=".4"/><column width=".6"/></columnspec>
308
309     <tr><th>Name</th><th>Description</th></tr>
310     <tr><td><code>TIME_YEAR</code></td>
311         <td>The current year (e.g. <code>2010</code>)</td></tr>
312     <tr><td><code>TIME_MON</code></td>
313         <td>The current month (<code>01</code>, ..., <code>12</code>)</td></tr>
314     <tr><td><code>TIME_DAY</code></td>
315         <td>The current day of the month (<code>01</code>, ...)</td></tr>
316     <tr><td><code>TIME_HOUR</code></td>
317         <td>The hour part of the current time
318             (<code>00</code>, ..., <code>23</code>)</td></tr>
319     <tr><td><code>TIME_MIN</code></td>
320         <td>The minute part of the current time </td></tr>
321     <tr><td><code>TIME_SEC</code></td>
322         <td>The second part of the current time </td></tr>
323     <tr><td><code>TIME_WDAY</code></td>
324         <td>The day of the week (starting with <code>0</code>
325             for Sunday)</td></tr>
326     <tr><td><code>TIME</code></td>
327         <td>The date and time in the format
328         <code>20101231235959</code></td></tr>
329     <tr><td><code>SERVER_SOFTWARE</code></td>
330         <td>The server version string</td></tr>
331     <tr><td><code>API_VERSION</code></td>
332         <td>The date of the API version (module magic number)</td></tr>
333     </table>
334
335     <p>Some modules register additional variables, see e.g.
336     <module>mod_ssl</module>.</p>
337
338 </section>
339
340 <section id="binop">
341     <title>Binary operators</title>
342
343     <p>With the exception of some built-in comparison operators, binary
344     operators have the form "<code>-[a-zA-Z][a-zA-Z0-9_]+</code>", i.e. a
345     minus and at least two characters. The name is not case sensitive.
346     Modules may register additional binary operators.</p>
347
348     <section id="comp">
349     <title>Comparison operators</title>
350
351     <table border="1" style="zebra">
352     <columnspec><column width=".2"/><column width=".2"/><column width=".6"/></columnspec>
353
354     <tr><th>Name</th><th>Alternative</th> <th>Description</th></tr>
355     <tr><td><code>==</code></td>
356         <td><code>=</code></td>
357         <td>String equality</td></tr>
358     <tr><td><code>!=</code></td>
359         <td></td>
360         <td>String inequality</td></tr>
361     <tr><td><code>&lt;</code></td>
362         <td></td>
363         <td>String less than</td></tr>
364     <tr><td><code>&lt;=</code></td>
365         <td></td>
366         <td>String less than or equal</td></tr>
367     <tr><td><code>&gt;</code></td>
368         <td></td>
369         <td>String greater than</td></tr>
370     <tr><td><code>&gt;=</code></td>
371         <td></td>
372         <td>String greater than or equal</td></tr>
373     <tr><td><code>=~</code></td>
374         <td></td>
375         <td>String matches the regular expression</td></tr>
376     <tr><td><code>!~</code></td>
377         <td></td>
378         <td>String does not match the regular expression</td></tr>
379     <tr><td><code>-eq</code></td>
380         <td><code>eq</code></td>
381         <td>Integer equality</td></tr>
382     <tr><td><code>-ne</code></td>
383         <td><code>ne</code></td>
384         <td>Integer inequality</td></tr>
385     <tr><td><code>-lt</code></td>
386         <td><code>lt</code></td>
387         <td>Integer less than</td></tr>
388     <tr><td><code>-le</code></td>
389         <td><code>le</code></td>
390         <td>Integer less than or equal</td></tr>
391     <tr><td><code>-gt</code></td>
392         <td><code>gt</code></td>
393         <td>Integer greater than</td></tr>
394     <tr><td><code>-ge</code></td>
395         <td><code>ge</code></td>
396         <td>Integer greater than or equal</td></tr>
397     </table>
398     </section>
399
400     <section id="binaryother">
401     <title>Other binary operators</title>
402
403     <table border="1" style="zebra">
404     <columnspec><column width=".2"/><column width=".8"/></columnspec>
405
406     <tr><th>Name</th><th>Description</th></tr>
407     <tr><td><code>-ipmatch</code></td>
408         <td>IP address matches address/netmask</td></tr>
409     <tr><td><code>-strmatch</code></td>
410         <td>left string matches pattern given by right string (containing
411             wildcards *, ?, [])</td></tr>
412     <tr><td><code>-strcmatch</code></td>
413         <td>same as <code>-strmatch</code>, but case insensitive</td></tr>
414     <tr><td><code>-fnmatch</code></td>
415         <td>same as <code>-strmatch</code>, but slashes are not matched by
416             wildcards</td></tr>
417     </table>
418     </section>
419
420 </section>
421
422 <section id="unnop">
423     <title>Unary operators</title>
424
425     <p>Unary operators take one argument and have the form
426     "<code>-[a-zA-Z]</code>", i.e. a minus and one character.
427     The name <em>is</em> case sensitive.
428     Modules may register additional unary operators.</p>
429
430     <table border="1" style="zebra">
431     <columnspec><column width=".2"/><column width=".2"/><column width=".6"/></columnspec>
432
433     <tr><th>Name</th><th>Description</th><th>Restricted</th></tr>
434     <tr><td><code>-d</code></td>
435         <td>The argument is treated as a filename.
436             True if the file exists and is a directory</td><td>yes</td></tr>
437     <tr><td><code>-e</code></td>
438         <td>The argument is treated as a filename.
439             True if the file (or dir or special) exists</td><td>yes</td></tr>
440     <tr><td><code>-f</code></td>
441         <td>The argument is treated as a filename.
442             True if the file exists and is regular file</td><td>yes</td></tr>
443     <tr><td><code>-s</code></td>
444         <td>The argument is treated as a filename.
445             True if the file exists and is not empty</td><td>yes</td></tr>
446     <tr><td><code>-L</code></td>
447         <td>The argument is treated as a filename.
448             True if the file exists and is symlink</td><td>yes</td></tr>
449     <tr><td><code>-h</code></td>
450         <td>The argument is treated as a filename.
451             True if the file exists and is symlink
452             (same as <code>-L</code>)</td><td>yes</td></tr>
453     <tr><td><code>-F</code></td>
454         <td>True if string is a valid file, accessible via all the server's
455             currently-configured access controls for that path. This uses an
456             internal subrequest to do the check, so use it with care - it can
457             impact your server's performance!</td><td></td></tr>
458     <tr><td><code>-U</code></td>
459         <td>True if string is a valid URL, accessible via all the server's
460             currently-configured access controls for that path. This uses an
461             internal subrequest to do the check, so use it with care - it can
462             impact your server's performance!</td><td></td></tr>
463     <tr><td><code>-A</code></td>
464         <td>Alias for <code>-U</code></td><td></td></tr>
465     <tr><td><code>-n</code></td>
466         <td>True if string is not empty</td><td></td></tr>
467     <tr><td><code>-z</code></td>
468         <td>True if string is empty</td><td></td></tr>
469     <tr><td><code>-T</code></td>
470         <td>False if string is empty, "<code>0</code>", "<code>off</code>",
471             "<code>false</code>", or "<code>no</code>" (case insensitive).
472             True otherwise.</td><td></td></tr>
473     <tr><td><code>-R</code></td>
474         <td>Same as "<code>%{REMOTE_ADDR} -ipmatch ...</code>", but more
475         efficient
476         </td><td></td></tr>
477     </table>
478
479     <p>The operators marked as "restricted" are not available in some modules
480     like <module>mod_include</module>.</p>
481 </section>
482
483 <section id="functions">
484     <title>Functions</title>
485
486     <p>Normal string-valued functions take one string as argument and return
487     a string. Functions names are not case sensitive.
488     Modules may register additional functions.</p>
489
490     <table border="1" style="zebra">
491     <columnspec><column width=".2"/><column width=".4"/><column width=".4"/></columnspec>
492
493     <tr><th>Name</th><th>Description</th><th>Special notes</th></tr>
494     <tr><td><code>req</code>, <code>http</code></td>
495         <td>Get HTTP request header; header names may be added to the Vary
496             header, see below</td><td></td></tr>
497     <tr><td><code>req_novary</code></td>
498         <td>Same as <code>req</code>, but header names will not be added to the
499             Vary header</td><td></td></tr>
500     <tr><td><code>resp</code></td>
501         <td>Get HTTP response header (most response headers will not yet be set
502             during <directive>&lt;If&gt;</directive>)</td><td></td></tr>
503     <tr><td><code>reqenv</code></td>
504         <td>Lookup request environment variable (as a shortcut,
505         <code>v</code> can also be used to access variables). 
506         </td>
507         <td>ordering</td></tr>
508     <tr><td><code>osenv</code></td>
509         <td>Lookup operating system environment variable</td><td></td></tr>
510     <tr><td><code>note</code></td>
511         <td>Lookup request note</td><td>ordering</td></tr>
512     <tr><td><code>env</code></td>
513         <td>Return first match of <code>note</code>, <code>reqenv</code>,
514             <code>osenv</code></td><td>ordering</td></tr>
515     <tr><td><code>tolower</code></td>
516         <td>Convert string to lower case</td><td></td></tr>
517     <tr><td><code>toupper</code></td>
518         <td>Convert string to upper case</td><td></td></tr>
519     <tr><td><code>escape</code></td>
520         <td>Escape special characters in %hex encoding</td><td></td></tr>
521     <tr><td><code>unescape</code></td>
522         <td>Unescape %hex encoded string, leaving encoded slashes alone;
523             return empty string if %00 is found</td><td></td></tr>
524     <tr><td><code>base64</code></td>
525         <td>Encode the string using base64 encoding</td><td></td></tr>
526     <tr><td><code>unbase64</code></td>
527         <td>Decode base64 encoded string, return truncated string if 0x00 is
528             found</td><td></td></tr>
529     <tr><td><code>md5</code></td>
530         <td>Hash the string using MD5, then encode the hash with hexadecimal
531             encoding</td><td></td></tr>
532     <tr><td><code>sha1</code></td>
533         <td>Hash the string using SHA1, then encode the hash with hexadecimal
534             encoding</td><td></td></tr>
535     <tr><td><code>file</code></td>
536         <td>Read contents from a file (including line endings, when present)
537         </td><td>restricted</td></tr>
538     <tr><td><code>filemod</code></td>
539         <td>Return last modification time of a file (or 0 if file does not exist
540             or is not regular file)</td><td>restricted</td></tr>
541     <tr><td><code>filesize</code></td>
542         <td>Return size of a file (or 0 if file does not exist or is not
543             regular file)</td><td>restricted</td></tr>
544     <tr><td><code>ldap</code></td>
545         <td>Escape characters as required by LDAP distinguished name escaping
546             (RFC4514) and LDAP filter escaping (RFC4515).</td><td></td></tr>
547     <tr><td><code>replace</code></td>
548         <td>replace(string, "from", "to") replaces all occurrences of "from"
549             in the string with "to".</td><td></td></tr>
550
551     </table>
552
553     <p>The functions marked as "restricted" in the final column are not 
554     available in some modules like <module>mod_include</module>.</p>
555
556     <p>The functions marked as "ordering" in the final column require some
557     consideration for the ordering of different components of the server,
558     especially when the function is used within the 
559     &lt;<directive module="core">If</directive>&gt; directive which is
560     evaluated relatively early.</p>
561     <note>
562     <title>Environment variable ordering</title>
563     When environment variables are looked up within an 
564     &lt;<directive module="core">If</directive>&gt; condition, it's important 
565     to consider how extremely early in request processing that this 
566     resolution occurs. As a guideline, any directive defined outside of virtual host 
567     context (directory, location, htaccess) is not likely to have yet had a 
568     chance to execute. <directive module="mod_setenvif">SetEnvIf</directive>
569     in virtual host scope is one directive that runs prior to this resolution
570     <br/>
571     <br/>
572     When <code>reqenv</code> is used outside of &lt;<directive module="core"
573     >If</directive>&gt;, the resolution will generally occur later, but the 
574     exact timing depends on the directive the expression has been used within.
575     </note>
576
577     <p>When the functions <code>req</code> or <code>http</code> are used,
578     the header name will automatically be added to the Vary header of the
579     HTTP response, except where otherwise noted for the directive accepting
580     the expression. The <code>req_novary</code> function can be used to
581     prevent names from being added to the Vary header.</p>
582
583     <p>In addition to string-valued functions, there are also
584     list-valued functions which take one string as argument and return a
585     wordlist, i.e. a list of strings. The wordlist can be used with the
586     special <code>-in</code> operator.  Functions names are not case
587     sensitive.  Modules may register additional functions.</p>
588
589     <p>There are no built-in list-valued functions. <module>mod_ssl</module>
590     provides <code>PeerExtList</code>.  See the description of
591     <directive module="mod_ssl">SSLRequire</directive> for details
592     (but <code>PeerExtList</code> is also usable outside
593     of <directive module="mod_ssl">SSLRequire</directive>).</p>
594
595 </section>
596
597 <section id="examples">
598
599     <title>Example expressions</title>
600     <p>The following examples show how expressions might be used to
601     evaluate requests:</p>
602
603     <!-- This section should probably be extended with more, useful examples -->
604     <highlight language="config">
605 # Compare the host name to example.com and redirect to www.example.com if it matches
606 &lt;If "%{HTTP_HOST} == 'example.com'"&gt;
607     Redirect permanent "/" "http://www.example.com/"
608 &lt;/If&gt;
609
610 # Force text/plain if requesting a file with the query string contains 'forcetext'
611 &lt;If "%{QUERY_STRING} =~ /forcetext/"&gt;
612     ForceType text/plain
613 &lt;/If&gt;
614
615 # Only allow access to this content during business hours
616 &lt;Directory "/foo/bar/business"&gt;
617     Require expr %{TIME_HOUR} -gt 9 &amp;&amp; %{TIME_HOUR} -lt 17
618 &lt;/Directory&gt;
619
620 # Check a HTTP header for a list of values
621 &lt;If "%{HTTP:X-example-header} in { 'foo', 'bar', 'baz' }"&gt;
622     Header set matched true
623 &lt;/If&gt;
624
625 # Check an environment variable for a regular expression, negated.
626 &lt;If "! reqenv('REDIRECT_FOO') =~ /bar/"&gt;
627     Header set matched true
628 &lt;/If&gt;
629
630 # Check result of URI mapping by running in Directory context with -f
631 &lt;Directory "/var/www"&gt;
632     AddEncoding x-gzip gz
633 &lt;If "-f '%{REQUEST_FILENAME}.unzipme' &amp;&amp; ! %{HTTP:Accept-Encoding} =~ /gzip/"&gt;
634       SetOutputFilter INFLATE
635 &lt;/If&gt;
636 &lt;/Directory&gt;
637
638 # Check against the client IP
639 &lt;If "-R '192.168.1.0/24'"&gt;
640     Header set matched true
641 &lt;/If&gt;
642
643 # Function examples in boolean context
644 &lt;If "md5('foo') == 'acbd18db4cc2f85cedef654fccc4a4d8'"&gt;
645   Header set checksum-matched true
646 &lt;/If&gt;
647 &lt;If "md5('foo') == replace('md5:XXXd18db4cc2f85cedef654fccc4a4d8', 'md5:XXX', 'acb')"&gt;
648   Header set checksum-matched-2 true
649 &lt;/If&gt;
650
651 # Function example in string context
652 Header set foo-checksum "expr=%{md5:foo}"
653
654 # This delays the evaluation of the condition clause compared to &lt;If&gt;
655 Header always set CustomHeader my-value "expr=%{REQUEST_URI} =~ m#^/special_path\.php$#"
656
657     </highlight>
658 </section>
659
660 <section id="other">
661     <title>Other</title>
662
663     <table border="1" style="zebra">
664     <columnspec><column width=".2"/><column width=".2"/><column width=".6"/></columnspec>
665
666     <tr><th>Name</th><th>Alternative</th> <th>Description</th></tr>
667     <tr><td><code>-in</code></td>
668         <td><code>in</code></td>
669         <td>string contained in wordlist</td></tr>
670     <tr><td><code>/regexp/</code></td>
671         <td><code>m#regexp#</code></td>
672         <td>Regular expression (the second form allows different
673         delimiters than /)</td></tr>
674     <tr><td><code>/regexp/i</code></td>
675         <td><code>m#regexp#i</code></td>
676         <td>Case insensitive regular expression</td></tr>
677     <tr><td><code>$0 ... $9</code></td>
678         <td></td>
679         <td>Regular expression backreferences</td></tr>
680     </table>
681
682     <section id="rebackref">
683         <title>Regular expression backreferences</title>
684         <p>The strings <code>$0</code> ... <code>$9</code> allow to reference
685         the capture groups from a previously executed, successfully
686         matching regular expressions. They can normally only be used in the
687         same expression as the matching regex, but some modules allow special
688         uses.</p>
689     </section>
690
691 </section>
692
693 <section id="sslrequire">
694     <title>Comparison with SSLRequire</title>
695     <p>The <em>ap_expr</em> syntax is mostly a superset of the syntax of the
696     deprecated <directive module="mod_ssl">SSLRequire</directive> directive.
697     The differences are described in <directive
698     module="mod_ssl">SSLRequire</directive>'s documentation.</p>
699 </section>
700
701 <section id="compatibility">
702     <title>Version History</title>
703     <p>The <code>req_novary</code> <a href="#functions">function</a>
704     is available for versions 2.4.4 and later.</p>
705     <p>The <code>SERVER_PROTOCOL_VERSION</code>,
706     <code>SERVER_PROTOCOL_VERSION_MAJOR</code> and
707     <code>SERVER_PROTOCOL_VERSION_MINOR</code>
708     <a href="#vars">variables</a>
709     are available for versions 2.5.0 and later.</p>
710 </section>
711
712 </manualpage>