]> granicus.if.org Git - apache/blob - docs/manual/expr.html.en
Update XForms.
[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 <meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type" />
5 <!--
6         XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
7               This file is generated from xml source: DO NOT EDIT
8         XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
9       -->
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">
15 </script>
16
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.gif" /></div>
22 <div class="up"><a href="./"><img title="&lt;-" alt="&lt;-" src="./images/left.gif" /></a></div>
23 <div id="path">
24 <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>
25 <div class="toplang">
26 <p><span>Available Languages: </span><a href="./en/expr.html" title="English">&nbsp;en&nbsp;</a> |
27 <a href="./fr/expr.html" hreflang="fr" rel="alternate" title="Français">&nbsp;fr&nbsp;</a></p>
28 </div>
29
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.
35     </p>
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>
39   </div>
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">&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>
50 <div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
51 <div class="section">
52 <h2><a name="grammar" id="grammar">Grammar in Backus-Naur Form notation</a></h2>
53     
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>.
62       </p>
63 <blockquote>
64 <pre>expr        ::= "<strong>true</strong>" | "<strong>false</strong>"
65               | "<strong>!</strong>" expr
66               | expr "<strong>&amp;&amp;</strong>" expr
67               | expr "<strong>||</strong>" expr
68               | "<strong>(</strong>" expr "<strong>)</strong>"
69               | comp
70
71 comp        ::= stringcomp
72               | integercomp
73               | unaryop word
74               | word binaryop word
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
79
80
81 stringcomp  ::= word "<strong>==</strong>" word
82               | word "<strong>!=</strong>" word
83               | word "<strong>&lt;</strong>"  word
84               | word "<strong>&lt;=</strong>" word
85               | word "<strong>&gt;</strong>"  word
86               | word "<strong>&gt;=</strong>" word
87
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
94
95 wordlist    ::= word
96               | wordlist "<strong>,</strong>" word
97
98 word        ::= word "<strong>.</strong>" word
99               | digit
100               | "<strong>'</strong>" string "<strong>'</strong>"
101               | "<strong>"</strong>" string "<strong>"</strong>"
102               | variable
103               | rebackref
104               | function
105
106 string      ::= stringpart
107               | string stringpart
108
109 stringpart  ::= cstring
110               | variable
111               | rebackref
112
113 cstring     ::= ...
114 digit       ::= [0-9]+
115
116 variable    ::= "<strong>%{</strong>" varname "<strong>}</strong>"
117               | "<strong>%{</strong>" funcname "<strong>:</strong>" funcargs "<strong>}</strong>"
118
119 rebackref   ::= "<strong>$</strong>" [0-9]
120
121 function     ::= funcname "<strong>(</strong>" wordlist "<strong>)</strong>"
122
123 listfunction ::= listfuncname "<strong>(</strong>" word "<strong>)</strong>"</pre>
124 </blockquote>
125
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>
129     
130
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">&lt;If &gt;</code>
135     directive is evaluated before authentication is done. Therefore,
136     <code>%{REMOTE_USER}</code> will not be set in this case.</p>
137
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
145     behavior.</p>
146
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>
155 </table>
156
157     <p>Other request related variables</p>
158
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.
181             </td></tr>
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">&lt;If&gt;</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">&lt;If&gt;</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>HTTPS</code></td>
241         <td>"<code>on</code>" if the request uses https,
242             "<code>off</code>" otherwise</td></tr>
243 <tr class="odd"><td><code>IPV6</code></td>
244         <td>"<code>on</code>" if the connection uses IPv6,
245             "<code>off</code>" otherwise</td></tr>
246 <tr><td><code>REQUEST_STATUS</code></td>
247         <td>The HTTP error status of the request (not available during <code class="directive">&lt;If&gt;</code>)</td></tr>
248 <tr class="odd"><td><code>REQUEST_LOG_ID</code></td>
249         <td>The error log id of the request (see
250             <code class="directive"><a href="./mod/core.html#errorlogformat">ErrorLogFormat</a></code>)</td></tr>
251 <tr><td><code>CONN_LOG_ID</code></td>
252         <td>The error log id of the connection (see
253             <code class="directive"><a href="./mod/core.html#errorlogformat">ErrorLogFormat</a></code>)</td></tr>
254 <tr class="odd"><td><code>CONN_REMOTE_ADDR</code></td>
255         <td>The peer IP address of the connection (see the
256             <code class="module"><a href="./mod/mod_remoteip.html">mod_remoteip</a></code> module)</td></tr>
257 <tr><td><code>CONTEXT_PREFIX</code></td>
258         <td /></tr>
259 <tr class="odd"><td><code>CONTEXT_DOCUMENT_ROOT</code></td>
260         <td /></tr>
261 </table>
262
263     <p>Misc variables</p>
264
265     <table class="bordered"><tr class="header"><th>Name</th><th>Description</th></tr>
266 <tr><td><code>TIME_YEAR</code></td>
267         <td>The current year (e.g. <code>2010</code>)</td></tr>
268 <tr class="odd"><td><code>TIME_MON</code></td>
269         <td>The current month (<code>1</code>, ..., <code>12</code>)</td></tr>
270 <tr><td><code>TIME_DAY</code></td>
271         <td>The current day of the month</td></tr>
272 <tr class="odd"><td><code>TIME_HOUR</code></td>
273         <td>The hour part of the current time
274             (<code>0</code>, ..., <code>23</code>)</td></tr>
275 <tr><td><code>TIME_MIN</code></td>
276         <td>The minute part of the current time </td></tr>
277 <tr class="odd"><td><code>TIME_SEC</code></td>
278         <td>The second part of the current time </td></tr>
279 <tr><td><code>TIME_WDAY</code></td>
280         <td>The day of the week (starting with <code>0</code>
281             for Sunday)</td></tr>
282 <tr class="odd"><td><code>TIME</code></td>
283         <td>The date and time in the format
284         <code>20101231235959</code></td></tr>
285 <tr><td><code>SERVER_SOFTWARE</code></td>
286         <td>The server version string</td></tr>
287 <tr class="odd"><td><code>API_VERSION</code></td>
288         <td>The date of the API version (module magic number)</td></tr>
289 </table>
290
291     <p>Some modules register additional variables, see e.g.
292     <code class="module"><a href="./mod/mod_ssl.html">mod_ssl</a></code>.</p>
293
294 </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
295 <div class="section">
296 <h2><a name="binop" id="binop">Binary operators</a></h2>
297     
298
299     <p>With the exception of some built-in comparison operators, binary
300     operators have the form "<code>-[a-zA-Z][a-zA-Z0-9_]+</code>", i.e. a
301     minus and at least two characters. The name is not case sensitive.
302     Modules may register additional binary operators.</p>
303
304     <h3><a name="comp" id="comp">Comparison operators</a></h3>
305     
306
307     <table class="bordered"><tr class="header"><th>Name</th><th>Alternative</th> <th>Description</th></tr>
308 <tr><td><code>==</code></td>
309         <td><code>=</code></td>
310         <td>String equality</td></tr>
311 <tr class="odd"><td><code>!=</code></td>
312         <td />
313         <td>String inequality</td></tr>
314 <tr><td><code>&lt;</code></td>
315         <td />
316         <td>String less than</td></tr>
317 <tr class="odd"><td><code>&lt;=</code></td>
318         <td />
319         <td>String less than or equal</td></tr>
320 <tr><td><code>&gt;</code></td>
321         <td />
322         <td>String greater than</td></tr>
323 <tr class="odd"><td><code>&gt;=</code></td>
324         <td />
325         <td>String greater than or equal</td></tr>
326 <tr><td><code>=~</code></td>
327         <td />
328         <td>String matches the regular expression</td></tr>
329 <tr class="odd"><td><code>!~</code></td>
330         <td />
331         <td>String does not match the regular expression</td></tr>
332 <tr><td><code>-eq</code></td>
333         <td><code>eq</code></td>
334         <td>Integer equality</td></tr>
335 <tr class="odd"><td><code>-ne</code></td>
336         <td><code>ne</code></td>
337         <td>Integer inequality</td></tr>
338 <tr><td><code>-lt</code></td>
339         <td><code>lt</code></td>
340         <td>Integer less than</td></tr>
341 <tr class="odd"><td><code>-le</code></td>
342         <td><code>le</code></td>
343         <td>Integer less than or equal</td></tr>
344 <tr><td><code>-gt</code></td>
345         <td><code>gt</code></td>
346         <td>Integer greater than</td></tr>
347 <tr class="odd"><td><code>-ge</code></td>
348         <td><code>ge</code></td>
349         <td>Integer greater than or equal</td></tr>
350 </table>
351     
352
353     <h3><a name="binaryother" id="binaryother">Other binary operators</a></h3>
354     
355
356     <table class="bordered"><tr class="header"><th>Name</th><th>Description</th></tr>
357 <tr><td><code>-ipmatch</code></td>
358         <td>IP address matches address/netmask</td></tr>
359 <tr class="odd"><td><code>-strmatch</code></td>
360         <td>left string matches pattern given by right string (containing
361             wildcards *, ?, [])</td></tr>
362 <tr><td><code>-strcmatch</code></td>
363         <td>same as <code>-strmatch</code>, but case insensitive</td></tr>
364 <tr class="odd"><td><code>-fnmatch</code></td>
365         <td>same as <code>-strmatch</code>, but slashes are not matched by
366             wildcards</td></tr>
367 </table>
368     
369
370 </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
371 <div class="section">
372 <h2><a name="unnop" id="unnop">Unary operators</a></h2>
373     
374
375     <p>Unary operators take one argument and have the form
376     "<code>-[a-zA-Z]</code>", i.e. a minus and one character.
377     The name <em>is</em> case sensitive.
378     Modules may register additional unary operators.</p>
379
380     <table class="bordered"><tr class="header"><th>Name</th><th>Description</th><th>Restricted</th></tr>
381 <tr><td><code>-d</code></td>
382         <td>The argument is treated as a filename.
383             True if the file exists and is a directory</td><td>yes</td></tr>
384 <tr class="odd"><td><code>-e</code></td>
385         <td>The argument is treated as a filename.
386             True if the file (or dir or special) exists</td><td>yes</td></tr>
387 <tr><td><code>-f</code></td>
388         <td>The argument is treated as a filename.
389             True if the file exists and is regular file</td><td>yes</td></tr>
390 <tr class="odd"><td><code>-s</code></td>
391         <td>The argument is treated as a filename.
392             True if the file exists and is not empty</td><td>yes</td></tr>
393 <tr><td><code>-L</code></td>
394         <td>The argument is treated as a filename.
395             True if the file exists and is symlink</td><td>yes</td></tr>
396 <tr class="odd"><td><code>-h</code></td>
397         <td>The argument is treated as a filename.
398             True if the file exists and is symlink
399             (same as <code>-L</code>)</td><td>yes</td></tr>
400 <tr><td><code>-F</code></td>
401         <td>True if string is a valid file, accessible via all the server's
402             currently-configured access controls for that path. This uses an
403             internal subrequest to do the check, so use it with care - it can
404             impact your server's performance!</td><td /></tr>
405 <tr class="odd"><td><code>-U</code></td>
406         <td>True if string is a valid URL, accessible via all the server's
407             currently-configured access controls for that path. This uses an
408             internal subrequest to do the check, so use it with care - it can
409             impact your server's performance!</td><td /></tr>
410 <tr><td><code>-A</code></td>
411         <td>Alias for <code>-U</code></td><td /></tr>
412 <tr class="odd"><td><code>-n</code></td>
413         <td>True if string is not empty</td><td /></tr>
414 <tr><td><code>-z</code></td>
415         <td>True if string is empty</td><td /></tr>
416 <tr class="odd"><td><code>-T</code></td>
417         <td>False if string is empty, "<code>0</code>", "<code>off</code>",
418             "<code>false</code>", or "<code>no</code>" (case insensitive).
419             True otherwise.</td><td /></tr>
420 <tr><td><code>-R</code></td>
421         <td>Same as "<code>%{REMOTE_ADDR} -ipmatch ...</code>", but more
422         efficient
423         </td><td /></tr>
424 </table>
425
426     <p>The operators marked as "restricted" are not available in some modules
427     like <code class="module"><a href="./mod/mod_include.html">mod_include</a></code>.</p>
428 </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
429 <div class="section">
430 <h2><a name="functions" id="functions">Functions</a></h2>
431     
432
433     <p>Normal string-valued functions take one string as argument and return
434     a string. Functions names are not case sensitive.
435     Modules may register additional functions.</p>
436
437     <table class="bordered"><tr class="header"><th>Name</th><th>Description</th><th>Restricted</th></tr>
438 <tr><td><code>req</code>, <code>http</code></td>
439         <td>Get HTTP request header; header names may be added to the Vary
440             header, see below</td><td /></tr>
441 <tr class="odd"><td><code>req_novary</code></td>
442         <td>Same as <code>req</code>, but header names will not be added to the
443             Vary header</td><td /></tr>
444 <tr><td><code>resp</code></td>
445         <td>Get HTTP response header (most response headers will not yet be set
446             during <code class="directive">&lt;If&gt;</code>)</td><td /></tr>
447 <tr class="odd"><td><code>reqenv</code></td>
448         <td>Lookup request environment variable (as a shortcut,
449         <code>v</code> can be used too to access
450         variables)</td><td /></tr>
451 <tr><td><code>osenv</code></td>
452         <td>Lookup operating system environment variable</td><td /></tr>
453 <tr class="odd"><td><code>note</code></td>
454         <td>Lookup request note</td><td /></tr>
455 <tr><td><code>env</code></td>
456         <td>Return first match of <code>note</code>, <code>reqenv</code>,
457             <code>osenv</code></td><td /></tr>
458 <tr class="odd"><td><code>tolower</code></td>
459         <td>Convert string to lower case</td><td /></tr>
460 <tr><td><code>toupper</code></td>
461         <td>Convert string to upper case</td><td /></tr>
462 <tr class="odd"><td><code>escape</code></td>
463         <td>Escape special characters in %hex encoding</td><td /></tr>
464 <tr><td><code>unescape</code></td>
465         <td>Unescape %hex encoded string, leaving encoded slashes alone;
466             return empty string if %00 is found</td><td /></tr>
467 <tr class="odd"><td><code>base64</code></td>
468         <td>Encode the string using base64 encoding</td><td /></tr>
469 <tr><td><code>unbase64</code></td>
470         <td>Decode base64 encoded string, return truncated string if 0x00 is
471             found</td><td /></tr>
472 <tr class="odd"><td><code>md5</code></td>
473         <td>Hash the string using MD5, then encode the hash with hexadecimal
474             encoding</td><td /></tr>
475 <tr><td><code>sha1</code></td>
476         <td>Hash the string using SHA1, then encode the hash with hexadecimal
477             encoding</td><td /></tr>
478 <tr class="odd"><td><code>file</code></td>
479         <td>Read contents from a file (including line endings, when present)
480         </td><td>yes</td></tr>
481 <tr><td><code>filemod</code></td>
482         <td>Return last modification time of a file (or 0 if file does not exist
483             or is not regular file)</td><td>yes</td></tr>
484 <tr class="odd"><td><code>filesize</code></td>
485         <td>Return size of a file (or 0 if file does not exist or is not
486             regular file)</td><td>yes</td></tr>
487 <tr><td><code>ldap</code></td>
488         <td>Escape characters as required by LDAP distinguished name escaping
489             (RFC4514) and LDAP filter escaping (RFC4515).</td><td /></tr>
490 <tr class="odd"><td><code>replace</code></td>
491         <td>replace(string, "from", "to") replaces all occurences of "from"
492             in the string with "to".</td><td /></tr>
493 </table>
494
495     <p>The functions marked as "restricted" are not available in some modules
496     like <code class="module"><a href="./mod/mod_include.html">mod_include</a></code>.</p>
497
498     <p>When the functions <code>req</code> or <code>http</code> are used,
499     the header name will automatically be added to the Vary header of the
500     HTTP response, except where otherwise noted for the directive accepting
501     the expression. The <code>req_novary</code> function can be used to
502     prevent names from being added to the Vary header.</p>
503
504     <p>In addition to string-valued functions, there are also
505     list-valued functions which take one string as argument and return a
506     wordlist, i.e. a list of strings. The wordlist can be used with the
507     special <code>-in</code> operator.  Functions names are not case
508     sensitive.  Modules may register additional functions.</p>
509
510     <p>There are no built-in list-valued functions. <code class="module"><a href="./mod/mod_ssl.html">mod_ssl</a></code>
511     provides <code>PeerExtList</code>.  See the description of
512     <code class="directive"><a href="./mod/mod_ssl.html#sslrequire">SSLRequire</a></code> for details
513     (but <code>PeerExtList</code> is also usable outside
514     of <code class="directive"><a href="./mod/mod_ssl.html#sslrequire">SSLRequire</a></code>).</p>
515
516 </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
517 <div class="section">
518 <h2><a name="examples" id="examples">Example expressions</a></h2>
519
520         
521     <p>The following examples show how expressions might be used to
522     evaluate requests:</p>
523
524         
525         <pre class="prettyprint lang-config"># Compare the host name to example.com and redirect to www.example.com if it matches
526 &lt;If "%{HTTP_HOST} == 'example.com'"&gt;
527     Redirect permanent "/" "http://www.example.com/"
528 &lt;/If&gt;
529
530 # Force text/plain if requesting a file with the query string contains 'forcetext'
531 &lt;If "%{QUERY_STRING} =~ /forcetext/"&gt;
532     ForceType text/plain
533 &lt;/If&gt;
534
535 # Only allow access to this content during business hours
536 &lt;Directory "/foo/bar/business"&gt;
537     Require expr %{TIME_HOUR} -gt 9 &amp;&amp; %{TIME_HOUR} -lt 17
538 &lt;/Directory&gt;
539
540 # Check a HTTP header for a list of values
541 &lt;If "%{HTTP:X-example-header} in { 'foo', 'bar', 'baz' }"&gt;
542     Header set matched true
543 &lt;/If&gt;
544
545 # Check an environment variable for a regular expression, negated.
546 &lt;If "! reqenv('REDIRECT_FOO') =~ /bar/"&gt;
547     Header set matched true
548 &lt;/If&gt;
549
550 # Check result of URI mapping by running in Directory context with -f
551 &lt;Directory "/var/www"&gt;
552     AddEncoding x-gzip gz
553 &lt;If "-f '%{REQUEST_FILENAME}.unzipme' &amp;&amp; ! %{HTTP:Accept-Encoding} =~ /gzip/"&gt;
554       SetOutputFilter INFLATE
555 &lt;/If&gt;
556 &lt;/Directory&gt;
557
558 # Function examples in boolean context
559 &lt;If "md5('foo') == 'acbd18db4cc2f85cedef654fccc4a4d8'"&gt;
560   Header set checksum-matched true
561 &lt;/If&gt;
562 &lt;If "md5('foo') == replace('md5:XXXd18db4cc2f85cedef654fccc4a4d8', 'md5:XXX', 'acb')&gt;
563   Header set checksum-matched-2 true
564 &lt;/If&gt;
565
566 # Function example in string context
567 Header set foo-checksum "expr=%{md5:foo}"
568
569 # This delays the evaluation of the condition clause compared to &lt;If&gt;
570 Header always set CustomHeader my-value "expr=%{REQUEST_URI} =~ m#^/special_path.php$#"</pre>
571
572 </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
573 <div class="section">
574 <h2><a name="other" id="other">Other</a></h2>
575     
576
577     <table class="bordered"><tr class="header"><th>Name</th><th>Alternative</th> <th>Description</th></tr>
578 <tr><td><code>-in</code></td>
579         <td><code>in</code></td>
580         <td>string contained in wordlist</td></tr>
581 <tr class="odd"><td><code>/regexp/</code></td>
582         <td><code>m#regexp#</code></td>
583         <td>Regular expression (the second form allows different
584         delimiters than /)</td></tr>
585 <tr><td><code>/regexp/i</code></td>
586         <td><code>m#regexp#i</code></td>
587         <td>Case insensitive regular expression</td></tr>
588 <tr class="odd"><td><code>$0 ... $9</code></td>
589         <td />
590         <td>Regular expression backreferences</td></tr>
591 </table>
592
593     <h3><a name="rebackref" id="rebackref">Regular expression backreferences</a></h3>
594         
595         <p>The strings <code>$0</code> ... <code>$9</code> allow to reference
596         the capture groups from a previously executed, successfully
597         matching regular expressions. They can normally only be used in the
598         same expression as the matching regex, but some modules allow special
599         uses.</p>
600     
601
602 </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
603 <div class="section">
604 <h2><a name="sslrequire" id="sslrequire">Comparison with SSLRequire</a></h2>
605     
606     <p>The <em>ap_expr</em> syntax is mostly a superset of the syntax of the
607     deprecated <code class="directive"><a href="./mod/mod_ssl.html#sslrequire">SSLRequire</a></code> directive.
608     The differences are described in <code class="directive"><a href="./mod/mod_ssl.html#sslrequire">SSLRequire</a></code>'s documentation.</p>
609 </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
610 <div class="section">
611 <h2><a name="compatibility" id="compatibility">Version History</a></h2>
612     
613     <p>The <code>req_novary</code> <a href="#functions">function</a>
614     is available for versions 2.4.4 and later.</p>
615     <p>The <code>SERVER_PROTOCOL_VERSION</code>,
616     <code>SERVER_PROTOCOL_VERSION_MAJOR</code> and
617     <code>SERVER_PROTOCOL_VERSION_MINOR</code>
618     <a href="#vars">variables</a>
619     are available for versions 2.5.0 and later.</p>
620 </div></div>
621 <div class="bottomlang">
622 <p><span>Available Languages: </span><a href="./en/expr.html" title="English">&nbsp;en&nbsp;</a> |
623 <a href="./fr/expr.html" hreflang="fr" rel="alternate" title="Français">&nbsp;fr&nbsp;</a></p>
624 </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>
625 <script type="text/javascript"><!--//--><![CDATA[//><!--
626 var comments_shortname = 'httpd';
627 var comments_identifier = 'http://httpd.apache.org/docs/trunk/expr.html';
628 (function(w, d) {
629     if (w.location.hostname.toLowerCase() == "httpd.apache.org") {
630         d.write('<div id="comments_thread"><\/div>');
631         var s = d.createElement('script');
632         s.type = 'text/javascript';
633         s.async = true;
634         s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier;
635         (d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s);
636     }
637     else {
638         d.write('<div id="comments_thread">Comments are disabled for this page at the moment.<\/div>');
639     }
640 })(window, document);
641 //--><!]]></script></div><div id="footer">
642 <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>
643 <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[//><!--
644 if (typeof(prettyPrint) !== 'undefined') {
645     prettyPrint();
646 }
647 //--><!]]></script>
648 </body></html>