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</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/directives.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.4</p> 19<img alt="" src="/images/feather.gif" /></div> 20<div class="up"><a href="./"><img title="<-" alt="<-" src="/images/left.gif" /></a></div> 21<div id="path"> 22<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.4</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"> en </a> | 25<a href="/fr/expr.html" hreflang="fr" rel="alternate" title="Fran�ais"> fr </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"><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/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_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_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>&&</strong>" expr 65 | expr "<strong>||</strong>" expr 66 | "<strong>(</strong>" expr "<strong>)</strong>" 67 | comp 68 69comp ::= 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 79stringcomp ::= word "<strong>==</strong>" word 80 | word "<strong>!=</strong>" word 81 | word "<strong><</strong>" word 82 | word "<strong><=</strong>" word 83 | word "<strong>></strong>" word 84 | word "<strong>>=</strong>" word 85 86integercomp ::= 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 93wordlist ::= word 94 | wordlist "<strong>,</strong>" word 95 96word ::= 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 104string ::= stringpart 105 | string stringpart 106 107stringpart ::= cstring 108 | variable 109 | rebackref 110 111cstring ::= ... 112digit ::= [0-9]+ 113 114variable ::= "<strong>%{</strong>" varname "<strong>}</strong>" 115 | "<strong>%{</strong>" funcname "<strong>:</strong>" funcargs "<strong>}</strong>" 116 117rebackref ::= "<strong>$</strong>" [0-9] 118 119function ::= funcname "<strong>(</strong>" word "<strong>)</strong>" 120 121listfunction ::= 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"><If ></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_FORWARDED</code></td></tr> 148<tr><td><code>HTTP_HOST</code></td></tr> 149<tr class="odd"><td><code>HTTP_PROXY_CONNECTION</code></td></tr> 150<tr><td><code>HTTP_REFERER</code></td></tr> 151<tr class="odd"><td><code>HTTP_USER_AGENT</code></td></tr> 152</table> 153 154 <p>Other request related variables</p> 155 156 <table class="bordered"><tr class="header"><th>Name</th><th>Description</th></tr> 157<tr><td><code>REQUEST_METHOD</code></td> 158 <td>The HTTP method of the incoming request (e.g. 159 <code>GET</code>)</td></tr> 160<tr class="odd"><td><code>REQUEST_SCHEME</code></td> 161 <td>The scheme part of the request's URI</td></tr> 162<tr><td><code>REQUEST_URI</code></td> 163 <td>The path part of the request's URI</td></tr> 164<tr class="odd"><td><code>DOCUMENT_URI</code></td> 165 <td>Same as REQUEST_URI</td></tr> 166<tr><td><code>REQUEST_FILENAME</code></td> 167 <td>The full local filesystem path to the file or script matching the 168 request, if this has already been determined by the server at the 169 time <code>REQUEST_FILENAME</code> is referenced. Otherwise, such 170 as when used in virtual host context, the same value as 171 <code>REQUEST_URI</code> </td></tr> 172<tr class="odd"><td><code>SCRIPT_FILENAME</code></td> 173 <td>Same as <code>REQUEST_FILENAME</code></td></tr> 174<tr><td><code>LAST_MODIFIED</code></td> 175 <td>The date and time of last modification of the file in the format 176 <code>20101231235959</code>, if this has already been determined by 177 the server at the time <code>LAST_MODIFIED</code> is referenced. 178 </td></tr> 179<tr class="odd"><td><code>SCRIPT_USER</code></td> 180 <td>The user name of the owner of the script.</td></tr> 181<tr><td><code>SCRIPT_GROUP</code></td> 182 <td>The group name of the group of the script.</td></tr> 183<tr class="odd"><td><code>PATH_INFO</code></td> 184 <td>The trailing path name information, see 185 <code class="directive"><a href="/mod/core.html#acceptpathinfo">AcceptPathInfo</a></code></td></tr> 186<tr><td><code>QUERY_STRING</code></td> 187 <td>The query string of the current request</td></tr> 188<tr class="odd"><td><code>IS_SUBREQ</code></td> 189 <td>"<code>true</code>" if the current request is a subrequest, 190 "<code>false</code>" otherwise</td></tr> 191<tr><td><code>THE_REQUEST</code></td> 192 <td>The complete request line (e.g., 193 "<code>GET /index.html HTTP/1.1</code>")</td></tr> 194<tr class="odd"><td><code>REMOTE_ADDR</code></td> 195 <td>The IP address of the remote host</td></tr> 196<tr><td><code>REMOTE_HOST</code></td> 197 <td>The host name of the remote host</td></tr> 198<tr class="odd"><td><code>REMOTE_USER</code></td> 199 <td>The name of the authenticated user (if any)</td></tr> 200<tr><td><code>REMOTE_IDENT</code></td> 201 <td>The user name set by <code class="module"><a href="/mod/mod_ident.html">mod_ident</a></code></td></tr> 202<tr class="odd"><td><code>SERVER_NAME</code></td> 203 <td>The <code class="directive"><a href="/mod/core.html#servername">ServerName</a></code> of 204 the current vhost</td></tr> 205<tr><td><code>SERVER_PORT</code></td> 206 <td>The server port of the current vhost, see 207 <code class="directive"><a href="/mod/core.html#servername">ServerName</a></code></td></tr> 208<tr class="odd"><td><code>SERVER_ADMIN</code></td> 209 <td>The <code class="directive"><a href="/mod/core.html#serveradmin">ServerAdmin</a></code> of 210 the current vhost</td></tr> 211<tr><td><code>SERVER_PROTOCOL</code></td> 212 <td>The protocol used by the request</td></tr> 213<tr class="odd"><td><code>DOCUMENT_ROOT</code></td> 214 <td>The <code class="directive"><a href="/mod/core.html#documentroot">DocumentRoot</a></code> of 215 the current vhost</td></tr> 216<tr><td><code>AUTH_TYPE</code></td> 217 <td>The configured <code class="directive"><a href="/mod/mod_authn_core.html#authtype">AuthType</a></code> (e.g. 218 "<code>basic</code>")</td></tr> 219<tr class="odd"><td><code>CONTENT_TYPE</code></td> 220 <td>The content type of the response</td></tr> 221<tr><td><code>HANDLER</code></td> 222 <td>The name of the <a href="handler.html">handler</a> creating 223 the response</td></tr> 224<tr class="odd"><td><code>HTTPS</code></td> 225 <td>"<code>on</code>" if the request uses https, 226 "<code>off</code>" otherwise</td></tr> 227<tr><td><code>IPV6</code></td> 228 <td>"<code>on</code>" if the connection uses IPv6, 229 "<code>off</code>" otherwise</td></tr> 230<tr class="odd"><td><code>REQUEST_STATUS</code></td> 231 <td>The HTTP error status of the request</td></tr> 232<tr><td><code>REQUEST_LOG_ID</code></td> 233 <td>The error log id of the request (see 234 <code class="directive"><a href="/mod/core.html#errorlogformat">ErrorLogFormat</a></code>)</td></tr> 235<tr class="odd"><td><code>CONN_LOG_ID</code></td> 236 <td>The error log id of the connection (see 237 <code class="directive"><a href="/mod/core.html#errorlogformat">ErrorLogFormat</a></code>)</td></tr> 238<tr><td><code>CONN_REMOTE_ADDR</code></td> 239 <td>The peer IP address of the connection (see the 240 <code class="module"><a href="/mod/mod_remoteip.html">mod_remoteip</a></code> module)</td></tr> 241</table> 242 243 <p>Misc variables</p> 244 245 <table class="bordered"><tr class="header"><th>Name</th><th>Description</th></tr> 246<tr><td><code>TIME_YEAR</code></td> 247 <td>The current year (e.g. <code>2010</code>)</td></tr> 248<tr class="odd"><td><code>TIME_MON</code></td> 249 <td>The current month (<code>1</code>, ..., <code>12</code>)</td></tr> 250<tr><td><code>TIME_DAY</code></td> 251 <td>The current day of the month</td></tr> 252<tr class="odd"><td><code>TIME_HOUR</code></td> 253 <td>The hour part of the current time 254 (<code>0</code>, ..., <code>23</code>)</td></tr> 255<tr><td><code>TIME_MIN</code></td> 256 <td>The minute part of the current time </td></tr> 257<tr class="odd"><td><code>TIME_SEC</code></td> 258 <td>The second part of the current time </td></tr> 259<tr><td><code>TIME_WDAY</code></td> 260 <td>The day of the week (starting with <code>0</code> 261 for Sunday)</td></tr> 262<tr class="odd"><td><code>TIME</code></td> 263 <td>The date and time in the format 264 <code>20101231235959</code></td></tr> 265<tr><td><code>SERVER_SOFTWARE</code></td> 266 <td>The server version string</td></tr> 267<tr class="odd"><td><code>API_VERSION</code></td> 268 <td>The date of the API version (module magic number)</td></tr> 269</table> 270 271 <p>Some modules register additional variables, see e.g. 272 <code class="module"><a href="/mod/mod_ssl.html">mod_ssl</a></code>.</p> 273 274</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div> 275<div class="section"> 276<h2><a name="binop" id="binop">Binary operators</a></h2> 277 278 279 <p>With the exception of some built-in comparison operators, binary 280 operators have the form "<code>-[a-zA-Z][a-zA-Z0-9_]+</code>", i.e. a 281 minus and at least two characters. The name is not case sensitive. 282 Modules may register additional binary operators.</p> 283 284 <h3><a name="comp" id="comp">Comparison operators</a></h3> 285 286 287 <table class="bordered"><tr class="header"><th>Name</th><th>Alternative</th> <th>Description</th></tr> 288<tr><td><code>==</code></td> 289 <td><code>=</code></td> 290 <td>String equality</td></tr> 291<tr class="odd"><td><code>!=</code></td> 292 <td /> 293 <td>String inequality</td></tr> 294<tr><td><code><</code></td> 295 <td /> 296 <td>String less than</td></tr> 297<tr class="odd"><td><code><=</code></td> 298 <td /> 299 <td>String less than or equal</td></tr> 300<tr><td><code>></code></td> 301 <td /> 302 <td>String greater than</td></tr> 303<tr class="odd"><td><code>>=</code></td> 304 <td /> 305 <td>String greater than or equal</td></tr> 306<tr><td><code>-eq</code></td> 307 <td><code>eq</code></td> 308 <td>Integer equality</td></tr> 309<tr class="odd"><td><code>-ne</code></td> 310 <td><code>ne</code></td> 311 <td>Integer inequality</td></tr> 312<tr><td><code>-lt</code></td> 313 <td><code>lt</code></td> 314 <td>Integer less than</td></tr> 315<tr class="odd"><td><code>-le</code></td> 316 <td><code>le</code></td> 317 <td>Integer less than or equal</td></tr> 318<tr><td><code>-gt</code></td> 319 <td><code>gt</code></td> 320 <td>Integer greater than</td></tr> 321<tr class="odd"><td><code>-ge</code></td> 322 <td><code>ge</code></td> 323 <td>Integer greater than or equal</td></tr> 324</table> 325 326 327 <h3><a name="binaryother" id="binaryother">Other binary operators</a></h3> 328 329 330 <table class="bordered"><tr class="header"><th>Name</th><th>Description</th></tr> 331<tr><td><code>-ipmatch</code></td> 332 <td>IP address matches address/netmask</td></tr> 333<tr class="odd"><td><code>-strmatch</code></td> 334 <td>left string matches pattern given by right string (containing 335 wildcards *, ?, [])</td></tr> 336<tr><td><code>-strcmatch</code></td> 337 <td>same as <code>-strmatch</code>, but case insensitive</td></tr> 338<tr class="odd"><td><code>-fnmatch</code></td> 339 <td>same as <code>-strmatch</code>, but slashes are not matched by 340 wildcards</td></tr> 341</table> 342 343 344</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div> 345<div class="section"> 346<h2><a name="unnop" id="unnop">Unary operators</a></h2> 347 348 349 <p>Unary operators take one argument and have the form 350 "<code>-[a-zA-Z]</code>", i.e. a minus and one character. 351 The name <em>is</em> case sensitive. 352 Modules may register additional unary operators.</p> 353 354 <table class="bordered"><tr class="header"><th>Name</th><th>Description</th><th>Restricted</th></tr> 355<tr><td><code>-d</code></td> 356 <td>The argument is treated as a filename. 357 True if the file exists and is a directory</td><td>yes</td></tr> 358<tr class="odd"><td><code>-e</code></td> 359 <td>The argument is treated as a filename. 360 True if the file (or dir or special) exists</td><td>yes</td></tr> 361<tr><td><code>-f</code></td> 362 <td>The argument is treated as a filename. 363 True if the file exists and is regular file</td><td>yes</td></tr> 364<tr class="odd"><td><code>-s</code></td> 365 <td>The argument is treated as a filename. 366 True if the file exists and is not empty</td><td>yes</td></tr> 367<tr><td><code>-L</code></td> 368 <td>The argument is treated as a filename. 369 True if the file exists and is symlink</td><td>yes</td></tr> 370<tr class="odd"><td><code>-h</code></td> 371 <td>The argument is treated as a filename. 372 True if the file exists and is symlink 373 (same as <code>-L</code>)</td><td>yes</td></tr> 374<tr><td><code>-F</code></td> 375 <td>True if string is a valid file, accessible via all the server's 376 currently-configured access controls for that path. This uses an 377 internal subrequest to do the check, so use it with care - it can 378 impact your server's performance!</td><td /></tr> 379<tr class="odd"><td><code>-U</code></td> 380 <td>True if string is a valid URL, accessible via all the server's 381 currently-configured access controls for that path. This uses an 382 internal subrequest to do the check, so use it with care - it can 383 impact your server's performance!</td><td /></tr> 384<tr><td><code>-A</code></td> 385 <td>Alias for <code>-U</code></td><td /></tr> 386<tr class="odd"><td><code>-n</code></td> 387 <td>True if string is not empty</td><td /></tr> 388<tr><td><code>-z</code></td> 389 <td>True if string is empty</td><td /></tr> 390<tr class="odd"><td><code>-T</code></td> 391 <td>False if string is empty, "<code>0</code>", "<code>off</code>", 392 "<code>false</code>", or "<code>no</code>" (case insensitive). 393 True otherwise.</td><td /></tr> 394<tr><td><code>-R</code></td> 395 <td>Same as "<code>%{REMOTE_ADDR} -ipmatch ...</code>", but more 396 efficient 397 </td><td /></tr> 398</table> 399 400 <p>The operators marked as "restricted" are not available in some modules 401 like <code class="module"><a href="/mod/mod_include.html">mod_include</a></code>.</p> 402</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div> 403<div class="section"> 404<h2><a name="functions" id="functions">Functions</a></h2> 405 406 407 <p>Normal string-valued functions take one string as argument and return 408 a string. Functions names are not case sensitive. 409 Modules may register additional functions.</p> 410 411 <table class="bordered"><tr class="header"><th>Name</th><th>Description</th><th>Restricted</th></tr> 412<tr><td><code>req</code>, <code>http</code></td> 413 <td>Get HTTP request header; header names may be added to the Vary 414 header, see below</td><td /></tr> 415<tr class="odd"><td><code>req_novary</code></td> 416 <td>Same as <code>req</code>, but header names will not be added to the 417 Vary header</td><td /></tr> 418<tr><td><code>resp</code></td> 419 <td>Get HTTP response header</td><td /></tr> 420<tr class="odd"><td><code>reqenv</code></td> 421 <td>Lookup request environment variable (as a shortcut, 422 <code>v</code> can be used too to access 423 variables).</td><td /></tr> 424<tr><td><code>osenv</code></td> 425 <td>Lookup operating system environment variable</td><td /></tr> 426<tr class="odd"><td><code>note</code></td> 427 <td>Lookup request note</td><td /></tr> 428<tr><td><code>env</code></td> 429 <td>Return first match of <code>note</code>, <code>reqenv</code>, 430 <code>osenv</code></td><td /></tr> 431<tr class="odd"><td><code>tolower</code></td> 432 <td>Convert string to lower case</td><td /></tr> 433<tr><td><code>toupper</code></td> 434 <td>Convert string to upper case</td><td /></tr> 435<tr class="odd"><td><code>escape</code></td> 436 <td>Escape special characters in %hex encoding</td><td /></tr> 437<tr><td><code>unescape</code></td> 438 <td>Unescape %hex encoded string, leaving encoded slashes alone; 439 return empty string if %00 is found</td><td /></tr> 440<tr class="odd"><td><code>base64</code></td> 441 <td>Encode the string using base64 encoding</td><td /></tr> 442<tr><td><code>unbase64</code></td> 443 <td>Decode base64 encoded string, return truncated string if 0x00 is 444 found</td><td /></tr> 445<tr class="odd"><td><code>md5</code></td> 446 <td>Hash the string using MD5, then encode the hash with hexadecimal 447 encoding</td><td /></tr> 448<tr><td><code>sha1</code></td> 449 <td>Hash the string using SHA1, then encode the hash with hexadecimal 450 encoding</td><td /></tr> 451<tr class="odd"><td><code>file</code></td> 452 <td>Read contents from a file</td><td>yes</td></tr> 453<tr><td><code>filesize</code></td> 454 <td>Return size of a file (or 0 if file does not exist or is not 455 regular file)</td><td>yes</td></tr> 456</table> 457 458 <p>The functions marked as "restricted" are not available in some modules 459 like <code class="module"><a href="/mod/mod_include.html">mod_include</a></code>.</p> 460 461 <p>When the functions <code>req</code> or <code>http</code> are used, 462 the header name will automatically be added to the Vary header of the 463 HTTP response, except where otherwise noted for the directive accepting 464 the expression. The <code>req_novary</code> function can be used to 465 prevent names from being added to the Vary header.</p> 466 467 <p>In addition to string-valued functions, there are also 468 list-valued functions which take one string as argument and return a 469 wordlist, i.e. a list of strings. The wordlist can be used with the 470 special <code>-in</code> operator. Functions names are not case 471 sensitive. Modules may register additional functions.</p> 472 473 <p>There are no built-in list-valued functions. <code class="module"><a href="/mod/mod_ssl.html">mod_ssl</a></code> 474 provides <code>PeerExtList</code>. See the description of 475 <code class="directive"><a href="/mod/mod_ssl.html#sslrequire">SSLRequire</a></code> for details 476 (but <code>PeerExtList</code> is also usable outside 477 of <code class="directive"><a href="/mod/mod_ssl.html#sslrequire">SSLRequire</a></code>).</p> 478 479</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div> 480<div class="section"> 481<h2><a name="examples" id="examples">Example expressions</a></h2> 482 483 484 <p>The following examples show how expressions might be used to 485 evaluate requests:</p> 486 487 <pre class="prettyprint lang-config"># Compare the host name to example.com and redirect to www.example.com if it matches 488<If "%{HTTP_HOST} == 'example.com'"> 489 Redirect permanent / http://www.example.com/ 490</If> 491 492# Force text/plain if requesting a file with the query string contains 'forcetext' 493<If "%{QUERY_STRING} =~ /forcetext/"> 494 ForceType text/plain 495</If> 496 497# Only allow access to this content during business hours 498<Directory "/foo/bar/business"> 499 Require expr %{TIME_HOUR} -gt 9 && %{TIME_HOUR} -lt 17 500</Directory></pre> 501 502</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div> 503<div class="section"> 504<h2><a name="other" id="other">Other</a></h2> 505 506 507 <table class="bordered"><tr class="header"><th>Name</th><th>Alternative</th> <th>Description</th></tr> 508<tr><td><code>-in</code></td> 509 <td><code>in</code></td> 510 <td>string contained in string list</td></tr> 511<tr class="odd"><td><code>/regexp/</code></td> 512 <td><code>m#regexp#</code></td> 513 <td>Regular expression (the second form allows different 514 delimiters than /)</td></tr> 515<tr><td><code>/regexp/i</code></td> 516 <td><code>m#regexp#i</code></td> 517 <td>Case insensitive regular expression</td></tr> 518<tr class="odd"><td><code>$0 ... $9</code></td> 519 <td /> 520 <td>Regular expression backreferences</td></tr> 521</table> 522 523 <h3><a name="rebackref" id="rebackref">Regular expression backreferences</a></h3> 524 525 <p>The strings <code>$0</code> ... <code>$9</code> allow to reference 526 the capture groups from a previously executed, successfully 527 matching regular expressions. They can normally only be used in the 528 same expression as the matching regex, but some modules allow special 529 uses.</p> 530 531 532</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div> 533<div class="section"> 534<h2><a name="sslrequire" id="sslrequire">Comparison with SSLRequire</a></h2> 535 536 <p>The <em>ap_expr</em> syntax is mostly a superset of the syntax of the 537 deprecated <code class="directive"><a href="/mod/mod_ssl.html#sslrequire">SSLRequire</a></code> directive. 538 The differences are described in <code class="directive"><a href="/mod/mod_ssl.html#sslrequire">SSLRequire</a></code>'s documentation.</p> 539</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div> 540<div class="section"> 541<h2><a name="compatibility" id="compatibility">Version History</a></h2> 542 543 <p>The <code>req_novary</code> <a href="#functions">function</a> 544 is available for versions 2.4.4 and later.</p> 545</div></div> 546<div class="bottomlang"> 547<p><span>Available Languages: </span><a href="/en/expr.html" title="English"> en </a> | 548<a href="/fr/expr.html" hreflang="fr" rel="alternate" title="Fran�ais"> fr </a></p> 549</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> 550<script type="text/javascript"><!--//--><![CDATA[//><!-- 551var comments_shortname = 'httpd'; 552var comments_identifier = 'http://httpd.apache.org/docs/2.4/expr.html'; 553(function(w, d) { 554 if (w.location.hostname.toLowerCase() == "httpd.apache.org") { 555 d.write('<div id="comments_thread"><\/div>'); 556 var s = d.createElement('script'); 557 s.type = 'text/javascript'; 558 s.async = true; 559 s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier; 560 (d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s); 561 } 562 else { 563 d.write('<div id="comments_thread">Comments are disabled for this page at the moment.<\/div>'); 564 } 565})(window, document); 566//--><!]]></script></div><div id="footer"> 567<p class="apache">Copyright 2014 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> 568<p class="menu"><a href="/mod/">Modules</a> | <a href="/mod/directives.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[//><!-- 569if (typeof(prettyPrint) !== 'undefined') { 570 prettyPrint(); 571} 572//--><!]]></script> 573</body></html>