]> granicus.if.org Git - apache/blob - docs/manual/expr.html.en
* Remove trailing whitespace from a bunch of *.xml files
[apache] / docs / manual / expr.html.en
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         XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
5               This file is generated from xml source: DO NOT EDIT
6         XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
7       -->
8 <title>Expressions in Apache HTTP Server - Apache HTTP Server Version 2.5</title>
9 <link href="./style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
10 <link href="./style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
11 <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" />
12 <script src="./style/scripts/prettify.min.js" type="text/javascript">
13 </script>
14
15 <link href="./images/favicon.ico" rel="shortcut icon" /></head>
16 <body id="manual-page"><div id="page-header">
17 <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>
18 <p class="apache">Apache HTTP Server Version 2.5</p>
19 <img alt="" src="./images/feather.gif" /></div>
20 <div class="up"><a href="./"><img title="&lt;-" alt="&lt;-" src="./images/left.gif" /></a></div>
21 <div id="path">
22 <a href="http://www.apache.org/">Apache</a> &gt; <a href="http://httpd.apache.org/">HTTP Server</a> &gt; <a href="http://httpd.apache.org/docs/">Documentation</a> &gt; <a href="./">Version 2.5</a></div><div id="page-content"><div id="preamble"><h1>Expressions in Apache HTTP Server</h1>
23 <div class="toplang">
24 <p><span>Available Languages: </span><a href="./en/expr.html" title="English">&nbsp;en&nbsp;</a> |
25 <a href="./fr/expr.html" hreflang="fr" rel="alternate" title="Français">&nbsp;fr&nbsp;</a></p>
26 </div>
27
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 <code class="directive"><a href="./mod/mod_ssl.html#sslrequire">SSLRequire</a></code> expressions can be replaced
36     by <a href="mod/mod_authz_core.html#reqexpr">Require expr</a>.  </p>
37   </div>
38 <div id="quickview"><ul id="toc"><li><img alt="" src="./images/down.gif" /> <a href="#grammar">Grammar in Backus-Naur Form notation</a></li>
39 <li><img alt="" src="./images/down.gif" /> <a href="#vars">Variables</a></li>
40 <li><img alt="" src="./images/down.gif" /> <a href="#binop">Binary operators</a></li>
41 <li><img alt="" src="./images/down.gif" /> <a href="#unnop">Unary operators</a></li>
42 <li><img alt="" src="./images/down.gif" /> <a href="#functions">Functions</a></li>
43 <li><img alt="" src="./images/down.gif" /> <a href="#examples">Example expressions</a></li>
44 <li><img alt="" src="./images/down.gif" /> <a href="#other">Other</a></li>
45 <li><img alt="" src="./images/down.gif" /> <a href="#sslrequire">Comparison with SSLRequire</a></li>
46 <li><img alt="" src="./images/down.gif" /> <a href="#compatibility">Version History</a></li>
47 </ul><h3>See also</h3><ul class="seealso"><li><code class="directive"><a href="./mod/core.html#if">&lt;If&gt;</a></code></li><li><code class="directive"><a href="./mod/core.html#elseif">&lt;ElseIf&gt;</a></code></li><li><code class="directive"><a href="./mod/core.html#else">&lt;Else&gt;</a></code></li><li><code class="directive"><a href="./mod/core.html#errordocument">&lt;ErrorDocument&gt;</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><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></ul><ul class="seealso"><li><a href="#comments_section">Comments</a></li></ul></div>
48 <div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
49 <div class="section">
50 <h2><a name="grammar" id="grammar">Grammar in Backus-Naur Form notation</a></h2>
51     
52       <p><a href="http://en.wikipedia.org/wiki/Backus%E2%80%93Naur_Form">Backus-Naur
53       Form</a> (BNF) is a notation technique for context-free grammars,
54       often used to describe the syntax of languages used in computing.
55       In most cases, expressions are used to express boolean values.
56       For these, the starting point in the BNF is <code>expr</code>.
57       However, a few directives like <code class="directive"><a href="./mod/mod_log_debug.html#logmessage">LogMessage</a></code> accept expressions
58       that evaluate to a string value. For those, the starting point in
59       the BNF is <code>string</code>.
60       </p>
61 <blockquote>
62 <pre>expr        ::= "<strong>true</strong>" | "<strong>false</strong>"
63               | "<strong>!</strong>" expr
64               | expr "<strong>&amp;&amp;</strong>" expr
65               | expr "<strong>||</strong>" expr
66               | "<strong>(</strong>" expr "<strong>)</strong>"
67               | comp
68
69 comp        ::= stringcomp
70               | integercomp
71               | unaryop word
72               | word binaryop word
73               | word "<strong>in</strong>" "<strong>{</strong>" wordlist "<strong>}</strong>"
74               | word "<strong>in</strong>" listfunction
75               | word "<strong>=~</strong>" regex
76               | word "<strong>!~</strong>" regex
77
78
79 stringcomp  ::= word "<strong>==</strong>" word
80               | word "<strong>!=</strong>" word
81               | word "<strong>&lt;</strong>"  word
82               | word "<strong>&lt;=</strong>" word
83               | word "<strong>&gt;</strong>"  word
84               | word "<strong>&gt;=</strong>" word
85
86 integercomp ::= word "<strong>-eq</strong>" word | word "<strong>eq</strong>" word
87               | word "<strong>-ne</strong>" word | word "<strong>ne</strong>" word
88               | word "<strong>-lt</strong>" word | word "<strong>lt</strong>" word
89               | word "<strong>-le</strong>" word | word "<strong>le</strong>" word
90               | word "<strong>-gt</strong>" word | word "<strong>gt</strong>" word
91               | word "<strong>-ge</strong>" word | word "<strong>ge</strong>" word
92
93 wordlist    ::= word
94               | wordlist "<strong>,</strong>" word
95
96 word        ::= word "<strong>.</strong>" word
97               | digit
98               | "<strong>'</strong>" string "<strong>'</strong>"
99               | "<strong>"</strong>" string "<strong>"</strong>"
100               | variable
101               | rebackref
102               | function
103
104 string      ::= stringpart
105               | string stringpart
106
107 stringpart  ::= cstring
108               | variable
109               | rebackref
110
111 cstring     ::= ...
112 digit       ::= [0-9]+
113
114 variable    ::= "<strong>%{</strong>" varname "<strong>}</strong>"
115               | "<strong>%{</strong>" funcname "<strong>:</strong>" funcargs "<strong>}</strong>"
116
117 rebackref   ::= "<strong>$</strong>" [0-9]
118
119 function     ::= funcname "<strong>(</strong>" wordlist "<strong>)</strong>"
120
121 listfunction ::= listfuncname "<strong>(</strong>" word "<strong>)</strong>"</pre>
122 </blockquote>
123
124 </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
125 <div class="section">
126 <h2><a name="vars" id="vars">Variables</a></h2>
127     
128
129     <p>The expression parser provides a number of variables of the form
130     <code>%{HTTP_HOST}</code>. Note that the value of a variable may depend
131     on the phase of the request processing in which it is evaluated.  For
132     example, an expression used in an <code class="directive">&lt;If &gt;</code>
133     directive is evaluated before authentication is done. Therefore,
134     <code>%{REMOTE_USER}</code> will not be set in this case.</p>
135
136     <p>The following variables provide the values of the named HTTP request
137     headers. The values of other headers can be obtained with the
138     <code>req</code> <a href="#functions">function</a>. Using these
139     variables may cause the header name to be added to the Vary
140     header of the HTTP response, except where otherwise noted for the
141     directive accepting the expression. The <code>req_novary</code>
142     <a href="#functions">function</a> may be used to circumvent this
143     behavior.</p>
144
145     <table class="bordered"><tr class="header"><th>Name</th></tr>
146 <tr><td><code>HTTP_ACCEPT</code></td></tr>
147 <tr class="odd"><td><code>HTTP_COOKIE</code></td></tr>
148 <tr><td><code>HTTP_FORWARDED</code></td></tr>
149 <tr class="odd"><td><code>HTTP_HOST</code></td></tr>
150 <tr><td><code>HTTP_PROXY_CONNECTION</code></td></tr>
151 <tr class="odd"><td><code>HTTP_REFERER</code></td></tr>
152 <tr><td><code>HTTP_USER_AGENT</code></td></tr>
153 </table>
154
155     <p>Other request related variables</p>
156
157     <table class="bordered"><tr class="header"><th>Name</th><th>Description</th></tr>
158 <tr><td><code>REQUEST_METHOD</code></td>
159         <td>The HTTP method of the incoming request (e.g.
160             <code>GET</code>)</td></tr>
161 <tr class="odd"><td><code>REQUEST_SCHEME</code></td>
162         <td>The scheme part of the request's URI</td></tr>
163 <tr><td><code>REQUEST_URI</code></td>
164         <td>The path part of the request's URI</td></tr>
165 <tr class="odd"><td><code>DOCUMENT_URI</code></td>
166         <td>Same as <code>REQUEST_URI</code></td></tr>
167 <tr><td><code>REQUEST_FILENAME</code></td>
168         <td>The full local filesystem path to the file or script matching the
169             request, if this has already been determined by the server at the
170             time <code>REQUEST_FILENAME</code> is referenced. Otherwise, such
171             as when used in virtual host context, the same value as
172             <code>REQUEST_URI</code> </td></tr>
173 <tr class="odd"><td><code>SCRIPT_FILENAME</code></td>
174         <td>Same as <code>REQUEST_FILENAME</code></td></tr>
175 <tr><td><code>LAST_MODIFIED</code></td>
176         <td>The date and time of last modification of the file in the format
177             <code>20101231235959</code>, if this has already been determined by
178             the server at the time <code>LAST_MODIFIED</code> is referenced.
179             </td></tr>
180 <tr class="odd"><td><code>SCRIPT_USER</code></td>
181         <td>The user name of the owner of the script.</td></tr>
182 <tr><td><code>SCRIPT_GROUP</code></td>
183         <td>The group name of the group of the script.</td></tr>
184 <tr class="odd"><td><code>PATH_INFO</code></td>
185         <td>The trailing path name information, see
186             <code class="directive"><a href="./mod/core.html#acceptpathinfo">AcceptPathInfo</a></code></td></tr>
187 <tr><td><code>QUERY_STRING</code></td>
188         <td>The query string of the current request</td></tr>
189 <tr class="odd"><td><code>IS_SUBREQ</code></td>
190         <td>"<code>true</code>" if the current request is a subrequest,
191             "<code>false</code>" otherwise</td></tr>
192 <tr><td><code>THE_REQUEST</code></td>
193         <td>The complete request line (e.g.,
194             "<code>GET /index.html HTTP/1.1</code>")</td></tr>
195 <tr class="odd"><td><code>REMOTE_ADDR</code></td>
196         <td>The IP address of the remote host</td></tr>
197 <tr><td><code>REMOTE_HOST</code></td>
198         <td>The host name of the remote host</td></tr>
199 <tr class="odd"><td><code>REMOTE_USER</code></td>
200         <td>The name of the authenticated user, if any (not available during <code class="directive">&lt;If&gt;</code>)</td></tr>
201 <tr><td><code>REMOTE_IDENT</code></td>
202         <td>The user name set by <code class="module"><a href="./mod/mod_ident.html">mod_ident</a></code></td></tr>
203 <tr class="odd"><td><code>SERVER_NAME</code></td>
204         <td>The <code class="directive"><a href="./mod/core.html#servername">ServerName</a></code> of
205             the current vhost</td></tr>
206 <tr><td><code>SERVER_PORT</code></td>
207         <td>The server port of the current vhost, see
208             <code class="directive"><a href="./mod/core.html#servername">ServerName</a></code></td></tr>
209 <tr class="odd"><td><code>SERVER_ADMIN</code></td>
210         <td>The <code class="directive"><a href="./mod/core.html#serveradmin">ServerAdmin</a></code> of
211             the current vhost</td></tr>
212 <tr><td><code>SERVER_PROTOCOL</code></td>
213         <td>The protocol used by the request (e.g. HTTP/1.1). In some types of
214             internal subrequests, this variable has the value
215             <code>INCLUDED</code>.</td></tr>
216 <tr class="odd"><td><code>SERVER_PROTOCOL_VERSION</code></td>
217         <td>A number that encodes the HTTP version of the request:
218             <code>1000 * major + minor</code>. For example, <code>1001</code>
219             corresponds to HTTP/1.1 and <code>9</code> corresponds
220             to HTTP/0.9</td></tr>
221 <tr><td><code>SERVER_PROTOCOL_VERSION_MAJOR</code></td>
222         <td>The major version part of the HTTP version of the request,
223             e.g. <code>1</code> for HTTP/1.0</td></tr>
224 <tr class="odd"><td><code>SERVER_PROTOCOL_VERSION_MINOR</code></td>
225         <td>The minor version part of the HTTP version of the request,
226             e.g. <code>0</code> for HTTP/1.0</td></tr>
227 <tr><td><code>DOCUMENT_ROOT</code></td>
228         <td>The <code class="directive"><a href="./mod/core.html#documentroot">DocumentRoot</a></code> of
229             the current vhost</td></tr>
230 <tr class="odd"><td><code>AUTH_TYPE</code></td>
231         <td>The configured <code class="directive"><a href="./mod/mod_authn_core.html#authtype">AuthType</a></code> (e.g.
232         "<code>basic</code>")</td></tr>
233 <tr><td><code>CONTENT_TYPE</code></td>
234         <td>The content type of the response (not available during <code class="directive">&lt;If&gt;</code>)</td></tr>
235 <tr class="odd"><td><code>HANDLER</code></td>
236         <td>The name of the <a href="handler.html">handler</a> creating
237             the response</td></tr>
238 <tr><td><code>HTTPS</code></td>
239         <td>"<code>on</code>" if the request uses https,
240             "<code>off</code>" otherwise</td></tr>
241 <tr class="odd"><td><code>IPV6</code></td>
242         <td>"<code>on</code>" if the connection uses IPv6,
243             "<code>off</code>" otherwise</td></tr>
244 <tr><td><code>REQUEST_STATUS</code></td>
245         <td>The HTTP error status of the request (not available during <code class="directive">&lt;If&gt;</code>)</td></tr>
246 <tr class="odd"><td><code>REQUEST_LOG_ID</code></td>
247         <td>The error log id of the request (see
248             <code class="directive"><a href="./mod/core.html#errorlogformat">ErrorLogFormat</a></code>)</td></tr>
249 <tr><td><code>CONN_LOG_ID</code></td>
250         <td>The error log id of the connection (see
251             <code class="directive"><a href="./mod/core.html#errorlogformat">ErrorLogFormat</a></code>)</td></tr>
252 <tr class="odd"><td><code>CONN_REMOTE_ADDR</code></td>
253         <td>The peer IP address of the connection (see the
254             <code class="module"><a href="./mod/mod_remoteip.html">mod_remoteip</a></code> module)</td></tr>
255 <tr><td><code>CONTEXT_PREFIX</code></td>
256         <td /></tr>
257 <tr class="odd"><td><code>CONTEXT_DOCUMENT_ROOT</code></td>
258         <td /></tr>
259 </table>
260
261     <p>Misc variables</p>
262
263     <table class="bordered"><tr class="header"><th>Name</th><th>Description</th></tr>
264 <tr><td><code>TIME_YEAR</code></td>
265         <td>The current year (e.g. <code>2010</code>)</td></tr>
266 <tr class="odd"><td><code>TIME_MON</code></td>
267         <td>The current month (<code>1</code>, ..., <code>12</code>)</td></tr>
268 <tr><td><code>TIME_DAY</code></td>
269         <td>The current day of the month</td></tr>
270 <tr class="odd"><td><code>TIME_HOUR</code></td>
271         <td>The hour part of the current time
272             (<code>0</code>, ..., <code>23</code>)</td></tr>
273 <tr><td><code>TIME_MIN</code></td>
274         <td>The minute part of the current time </td></tr>
275 <tr class="odd"><td><code>TIME_SEC</code></td>
276         <td>The second part of the current time </td></tr>
277 <tr><td><code>TIME_WDAY</code></td>
278         <td>The day of the week (starting with <code>0</code>
279             for Sunday)</td></tr>
280 <tr class="odd"><td><code>TIME</code></td>
281         <td>The date and time in the format
282         <code>20101231235959</code></td></tr>
283 <tr><td><code>SERVER_SOFTWARE</code></td>
284         <td>The server version string</td></tr>
285 <tr class="odd"><td><code>API_VERSION</code></td>
286         <td>The date of the API version (module magic number)</td></tr>
287 </table>
288
289     <p>Some modules register additional variables, see e.g.
290     <code class="module"><a href="./mod/mod_ssl.html">mod_ssl</a></code>.</p>
291
292 </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
293 <div class="section">
294 <h2><a name="binop" id="binop">Binary operators</a></h2>
295     
296
297     <p>With the exception of some built-in comparison operators, binary
298     operators have the form "<code>-[a-zA-Z][a-zA-Z0-9_]+</code>", i.e. a
299     minus and at least two characters. The name is not case sensitive.
300     Modules may register additional binary operators.</p>
301
302     <h3><a name="comp" id="comp">Comparison operators</a></h3>
303     
304
305     <table class="bordered"><tr class="header"><th>Name</th><th>Alternative</th> <th>Description</th></tr>
306 <tr><td><code>==</code></td>
307         <td><code>=</code></td>
308         <td>String equality</td></tr>
309 <tr class="odd"><td><code>!=</code></td>
310         <td />
311         <td>String inequality</td></tr>
312 <tr><td><code>&lt;</code></td>
313         <td />
314         <td>String less than</td></tr>
315 <tr class="odd"><td><code>&lt;=</code></td>
316         <td />
317         <td>String less than or equal</td></tr>
318 <tr><td><code>&gt;</code></td>
319         <td />
320         <td>String greater than</td></tr>
321 <tr class="odd"><td><code>&gt;=</code></td>
322         <td />
323         <td>String greater than or equal</td></tr>
324 <tr><td><code>=~</code></td>
325         <td />
326         <td>String matches the regular expression</td></tr>
327 <tr class="odd"><td><code>!~</code></td>
328         <td />
329         <td>String does not match the regular expression</td></tr>
330 <tr><td><code>-eq</code></td>
331         <td><code>eq</code></td>
332         <td>Integer equality</td></tr>
333 <tr class="odd"><td><code>-ne</code></td>
334         <td><code>ne</code></td>
335         <td>Integer inequality</td></tr>
336 <tr><td><code>-lt</code></td>
337         <td><code>lt</code></td>
338         <td>Integer less than</td></tr>
339 <tr class="odd"><td><code>-le</code></td>
340         <td><code>le</code></td>
341         <td>Integer less than or equal</td></tr>
342 <tr><td><code>-gt</code></td>
343         <td><code>gt</code></td>
344         <td>Integer greater than</td></tr>
345 <tr class="odd"><td><code>-ge</code></td>
346         <td><code>ge</code></td>
347         <td>Integer greater than or equal</td></tr>
348 </table>
349     
350
351     <h3><a name="binaryother" id="binaryother">Other binary operators</a></h3>
352     
353
354     <table class="bordered"><tr class="header"><th>Name</th><th>Description</th></tr>
355 <tr><td><code>-ipmatch</code></td>
356         <td>IP address matches address/netmask</td></tr>
357 <tr class="odd"><td><code>-strmatch</code></td>
358         <td>left string matches pattern given by right string (containing
359             wildcards *, ?, [])</td></tr>
360 <tr><td><code>-strcmatch</code></td>
361         <td>same as <code>-strmatch</code>, but case insensitive</td></tr>
362 <tr class="odd"><td><code>-fnmatch</code></td>
363         <td>same as <code>-strmatch</code>, but slashes are not matched by
364             wildcards</td></tr>
365 </table>
366     
367
368 </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
369 <div class="section">
370 <h2><a name="unnop" id="unnop">Unary operators</a></h2>
371     
372
373     <p>Unary operators take one argument and have the form
374     "<code>-[a-zA-Z]</code>", i.e. a minus and one character.
375     The name <em>is</em> case sensitive.
376     Modules may register additional unary operators.</p>
377
378     <table class="bordered"><tr class="header"><th>Name</th><th>Description</th><th>Restricted</th></tr>
379 <tr><td><code>-d</code></td>
380         <td>The argument is treated as a filename.
381             True if the file exists and is a directory</td><td>yes</td></tr>
382 <tr class="odd"><td><code>-e</code></td>
383         <td>The argument is treated as a filename.
384             True if the file (or dir or special) exists</td><td>yes</td></tr>
385 <tr><td><code>-f</code></td>
386         <td>The argument is treated as a filename.
387             True if the file exists and is regular file</td><td>yes</td></tr>
388 <tr class="odd"><td><code>-s</code></td>
389         <td>The argument is treated as a filename.
390             True if the file exists and is not empty</td><td>yes</td></tr>
391 <tr><td><code>-L</code></td>
392         <td>The argument is treated as a filename.
393             True if the file exists and is symlink</td><td>yes</td></tr>
394 <tr class="odd"><td><code>-h</code></td>
395         <td>The argument is treated as a filename.
396             True if the file exists and is symlink
397             (same as <code>-L</code>)</td><td>yes</td></tr>
398 <tr><td><code>-F</code></td>
399         <td>True if string is a valid file, accessible via all the server's
400             currently-configured access controls for that path. This uses an
401             internal subrequest to do the check, so use it with care - it can
402             impact your server's performance!</td><td /></tr>
403 <tr class="odd"><td><code>-U</code></td>
404         <td>True if string is a valid URL, 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><td><code>-A</code></td>
409         <td>Alias for <code>-U</code></td><td /></tr>
410 <tr class="odd"><td><code>-n</code></td>
411         <td>True if string is not empty</td><td /></tr>
412 <tr><td><code>-z</code></td>
413         <td>True if string is empty</td><td /></tr>
414 <tr class="odd"><td><code>-T</code></td>
415         <td>False if string is empty, "<code>0</code>", "<code>off</code>",
416             "<code>false</code>", or "<code>no</code>" (case insensitive).
417             True otherwise.</td><td /></tr>
418 <tr><td><code>-R</code></td>
419         <td>Same as "<code>%{REMOTE_ADDR} -ipmatch ...</code>", but more
420         efficient
421         </td><td /></tr>
422 </table>
423
424     <p>The operators marked as "restricted" are not available in some modules
425     like <code class="module"><a href="./mod/mod_include.html">mod_include</a></code>.</p>
426 </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
427 <div class="section">
428 <h2><a name="functions" id="functions">Functions</a></h2>
429     
430
431     <p>Normal string-valued functions take one string as argument and return
432     a string. Functions names are not case sensitive.
433     Modules may register additional functions.</p>
434
435     <table class="bordered"><tr class="header"><th>Name</th><th>Description</th><th>Restricted</th></tr>
436 <tr><td><code>req</code>, <code>http</code></td>
437         <td>Get HTTP request header; header names may be added to the Vary
438             header, see below</td><td /></tr>
439 <tr class="odd"><td><code>req_novary</code></td>
440         <td>Same as <code>req</code>, but header names will not be added to the
441             Vary header</td><td /></tr>
442 <tr><td><code>resp</code></td>
443         <td>Get HTTP response header (most response headers will not yet be set
444             during <code class="directive">&lt;If&gt;</code>)</td><td /></tr>
445 <tr class="odd"><td><code>reqenv</code></td>
446         <td>Lookup request environment variable (as a shortcut,
447         <code>v</code> can be used too to access
448         variables)</td><td /></tr>
449 <tr><td><code>osenv</code></td>
450         <td>Lookup operating system environment variable</td><td /></tr>
451 <tr class="odd"><td><code>note</code></td>
452         <td>Lookup request note</td><td /></tr>
453 <tr><td><code>env</code></td>
454         <td>Return first match of <code>note</code>, <code>reqenv</code>,
455             <code>osenv</code></td><td /></tr>
456 <tr class="odd"><td><code>tolower</code></td>
457         <td>Convert string to lower case</td><td /></tr>
458 <tr><td><code>toupper</code></td>
459         <td>Convert string to upper case</td><td /></tr>
460 <tr class="odd"><td><code>escape</code></td>
461         <td>Escape special characters in %hex encoding</td><td /></tr>
462 <tr><td><code>unescape</code></td>
463         <td>Unescape %hex encoded string, leaving encoded slashes alone;
464             return empty string if %00 is found</td><td /></tr>
465 <tr class="odd"><td><code>base64</code></td>
466         <td>Encode the string using base64 encoding</td><td /></tr>
467 <tr><td><code>unbase64</code></td>
468         <td>Decode base64 encoded string, return truncated string if 0x00 is
469             found</td><td /></tr>
470 <tr class="odd"><td><code>md5</code></td>
471         <td>Hash the string using MD5, then encode the hash with hexadecimal
472             encoding</td><td /></tr>
473 <tr><td><code>sha1</code></td>
474         <td>Hash the string using SHA1, then encode the hash with hexadecimal
475             encoding</td><td /></tr>
476 <tr class="odd"><td><code>file</code></td>
477         <td>Read contents from a file (including line endings, when present)
478         </td><td>yes</td></tr>
479 <tr><td><code>filemod</code></td>
480         <td>Return last modification time of a file (or 0 if file does not exist
481             or is not regular file)</td><td>yes</td></tr>
482 <tr class="odd"><td><code>filesize</code></td>
483         <td>Return size of a file (or 0 if file does not exist or is not
484             regular file)</td><td>yes</td></tr>
485 <tr><td><code>ldap</code></td>
486         <td>Escape characters as required by LDAP distinguished name escaping
487             (RFC4514) and LDAP filter escaping (RFC4515).</td><td /></tr>
488 <tr class="odd"><td><code>replace</code></td>
489         <td>replace(string, "from", "to") replaces all occurences of "from"
490             in the string with "to".</td><td /></tr>
491 </table>
492
493     <p>The functions marked as "restricted" are not available in some modules
494     like <code class="module"><a href="./mod/mod_include.html">mod_include</a></code>.</p>
495
496     <p>When the functions <code>req</code> or <code>http</code> are used,
497     the header name will automatically be added to the Vary header of the
498     HTTP response, except where otherwise noted for the directive accepting
499     the expression. The <code>req_novary</code> function can be used to
500     prevent names from being added to the Vary header.</p>
501
502     <p>In addition to string-valued functions, there are also
503     list-valued functions which take one string as argument and return a
504     wordlist, i.e. a list of strings. The wordlist can be used with the
505     special <code>-in</code> operator.  Functions names are not case
506     sensitive.  Modules may register additional functions.</p>
507
508     <p>There are no built-in list-valued functions. <code class="module"><a href="./mod/mod_ssl.html">mod_ssl</a></code>
509     provides <code>PeerExtList</code>.  See the description of
510     <code class="directive"><a href="./mod/mod_ssl.html#sslrequire">SSLRequire</a></code> for details
511     (but <code>PeerExtList</code> is also usable outside
512     of <code class="directive"><a href="./mod/mod_ssl.html#sslrequire">SSLRequire</a></code>).</p>
513
514 </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
515 <div class="section">
516 <h2><a name="examples" id="examples">Example expressions</a></h2>
517
518         
519     <p>The following examples show how expressions might be used to
520     evaluate requests:</p>
521
522         
523         <pre class="prettyprint lang-config"># Compare the host name to example.com and redirect to www.example.com if it matches
524 &lt;If "%{HTTP_HOST} == 'example.com'"&gt;
525     Redirect permanent "/" "http://www.example.com/"
526 &lt;/If&gt;
527
528 # Force text/plain if requesting a file with the query string contains 'forcetext'
529 &lt;If "%{QUERY_STRING} =~ /forcetext/"&gt;
530     ForceType text/plain
531 &lt;/If&gt;
532
533 # Only allow access to this content during business hours
534 &lt;Directory "/foo/bar/business"&gt;
535     Require expr %{TIME_HOUR} -gt 9 &amp;&amp; %{TIME_HOUR} -lt 17
536 &lt;/Directory&gt;
537
538 # Check a HTTP header for a list of values
539 &lt;If "%{HTTP:X-example-header} in { 'foo', 'bar', 'baz' }"&gt;
540     Header set matched true
541 &lt;/If&gt;
542
543 # Check an environment variable for a regular expression, negated.
544 &lt;If "! reqenv('REDIRECT_FOO') =~ /bar/"&gt;
545     Header set matched true
546 &lt;/If&gt;
547
548 # Check result of URI mapping by running in Directory context with -f
549 &lt;Directory "/var/www"&gt;
550     AddEncoding x-gzip gz
551 &lt;If "-f '%{REQUEST_FILENAME}.unzipme' &amp;&amp; ! %{HTTP:Accept-Encoding} =~ /gzip/"&gt;
552       SetOutputFilter INFLATE
553 &lt;/If&gt;
554 &lt;/Directory&gt;
555
556 # Function examples in boolean context
557 &lt;If "md5('foo') == 'acbd18db4cc2f85cedef654fccc4a4d8'"&gt;
558   Header set checksum-matched true
559 &lt;/If&gt;
560 &lt;If "md5('foo') == replace('md5:XXXd18db4cc2f85cedef654fccc4a4d8', 'md5:XXX', 'acb')&gt;
561   Header set checksum-matched-2 true
562 &lt;/If&gt;
563
564 # Function example in string context
565 Header set foo-checksum "expr=%{md5:foo}"</pre>
566
567 </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
568 <div class="section">
569 <h2><a name="other" id="other">Other</a></h2>
570     
571
572     <table class="bordered"><tr class="header"><th>Name</th><th>Alternative</th> <th>Description</th></tr>
573 <tr><td><code>-in</code></td>
574         <td><code>in</code></td>
575         <td>string contained in wordlist</td></tr>
576 <tr class="odd"><td><code>/regexp/</code></td>
577         <td><code>m#regexp#</code></td>
578         <td>Regular expression (the second form allows different
579         delimiters than /)</td></tr>
580 <tr><td><code>/regexp/i</code></td>
581         <td><code>m#regexp#i</code></td>
582         <td>Case insensitive regular expression</td></tr>
583 <tr class="odd"><td><code>$0 ... $9</code></td>
584         <td />
585         <td>Regular expression backreferences</td></tr>
586 </table>
587
588     <h3><a name="rebackref" id="rebackref">Regular expression backreferences</a></h3>
589         
590         <p>The strings <code>$0</code> ... <code>$9</code> allow to reference
591         the capture groups from a previously executed, successfully
592         matching regular expressions. They can normally only be used in the
593         same expression as the matching regex, but some modules allow special
594         uses.</p>
595     
596
597 </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
598 <div class="section">
599 <h2><a name="sslrequire" id="sslrequire">Comparison with SSLRequire</a></h2>
600     
601     <p>The <em>ap_expr</em> syntax is mostly a superset of the syntax of the
602     deprecated <code class="directive"><a href="./mod/mod_ssl.html#sslrequire">SSLRequire</a></code> directive.
603     The differences are described in <code class="directive"><a href="./mod/mod_ssl.html#sslrequire">SSLRequire</a></code>'s documentation.</p>
604 </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
605 <div class="section">
606 <h2><a name="compatibility" id="compatibility">Version History</a></h2>
607     
608     <p>The <code>req_novary</code> <a href="#functions">function</a>
609     is available for versions 2.4.4 and later.</p>
610     <p>The <code>SERVER_PROTOCOL_VERSION</code>,
611     <code>SERVER_PROTOCOL_VERSION_MAJOR</code> and
612     <code>SERVER_PROTOCOL_VERSION_MINOR</code>
613     <a href="#vars">variables</a>
614     are available for versions 2.5.0 and later.</p>
615 </div></div>
616 <div class="bottomlang">
617 <p><span>Available Languages: </span><a href="./en/expr.html" title="English">&nbsp;en&nbsp;</a> |
618 <a href="./fr/expr.html" hreflang="fr" rel="alternate" title="Français">&nbsp;fr&nbsp;</a></p>
619 </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&amp;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>
620 <script type="text/javascript"><!--//--><![CDATA[//><!--
621 var comments_shortname = 'httpd';
622 var comments_identifier = 'http://httpd.apache.org/docs/trunk/expr.html';
623 (function(w, d) {
624     if (w.location.hostname.toLowerCase() == "httpd.apache.org") {
625         d.write('<div id="comments_thread"><\/div>');
626         var s = d.createElement('script');
627         s.type = 'text/javascript';
628         s.async = true;
629         s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier;
630         (d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s);
631     }
632     else {
633         d.write('<div id="comments_thread">Comments are disabled for this page at the moment.<\/div>');
634     }
635 })(window, document);
636 //--><!]]></script></div><div id="footer">
637 <p class="apache">Copyright 2015 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>
638 <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[//><!--
639 if (typeof(prettyPrint) !== 'undefined') {
640     prettyPrint();
641 }
642 //--><!]]></script>
643 </body></html>