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