Expressions in Apache HTTP Server - Apache HTTP Server Version 2.4
Modules | Directives | FAQ | Glossary | Sitemap | Report a bug Apache HTTP Server Version 2.4 Apache > HTTP Server > Documentation > Version 2.4 Expressions in Apache HTTP Server Available Languages: en | fr Historically, there are several syntax variants for expressions used to express a condition in the different modules of the Apache HTTP Server. There is some ongoing effort to only use a single variant, called ap_expr , for all configuration directives.
This document describes the ap_expr expression parser. The ap_expr expression is intended to replace most other expression variants in HTTPD. For example, the deprecated SSLRequire expressions can be replaced by Require expr . Grammar in Backus-Naur Form notation Variables Binary operators Unary operators Functions Example expressions Other Comparison with SSLRequire Version History See also <If> <ElseIf> <Else> ErrorDocument Alias ScriptAlias Redirect AuthBasicFake AuthFormLoginRequiredLocation AuthFormLoginSuccessLocation AuthFormLogoutLocation AuthName AuthType RewriteCond SetEnvIfExpr Header RequestHeader FilterProvider Require expr Require ldap-user Require ldap-group Require ldap-dn Require ldap-attribute Require ldap-filter Require ldap-search Require dbd-group Require dbm-group Require group Require host SSLRequire LogMessage mod_include Environment Variables in Apache httpd Grammar in Backus-Naur Form notation ¶ Backus-Naur Form (BNF) is a notation technique for context-free grammars, often used to describe the syntax of languages used in computing.
In most cases, expressions are used to express boolean values. For these, the starting point in the BNF is expr . However, a few directives like LogMessage accept expressions that evaluate to a string value. For those, the starting point in the BNF is string . expr ::= " true " | " false " | " ! " expr | expr " && " expr | expr " || " expr | " ( " expr " ) " | comp comp ::= stringcomp | integercomp | unaryop word | word binaryop word | word " in " " { " wordlist " } " | word " in " listfunction | word " =~ " regex | word " !~ " regex stringcomp ::= word " == " word | word " != " word | word " < " word | word " <= " word | word " > " word | word " >= " word integercomp ::= word " -eq " word | word " eq " word | word " -ne " word | word " ne " word | word " -lt " word | word " lt " word | word " -le " word | word " le " word | word " -gt " word | word " gt " word | word " -ge " word | word " ge " word wordlist ::= word | wordlist " , " word word ::= word " .
" word | digit | " ' " string " ' " | " " " string " " " | variable | rebackref | function string ::= stringpart | string stringpart stringpart ::= cstring | variable | rebackref cstring ::= ... digit ::= [0-9]+ variable ::= " %{ " varname " } " | " %{ " funcname " : " funcargs " } " rebackref ::= " $ " [0-9] function ::= funcname " ( " word " ) " listfunction ::= listfuncname " ( " word " ) " Variables ¶ The expression parser provides a number of variables of the form %{HTTP_HOST} .
Note that the value of a variable may depend on the phase of the request processing in which it is evaluated. For example, an expression used in an <If > directive is evaluated before authentication is done. Therefore, %{REMOTE_USER} will not be set in this case. For information on setting and manipulating request environment variables (using SetEnv , SetEnvIf , mod_rewrite 's [E=...] flag, and others), see Environment Variables in Apache httpd .
The following variables provide the values of the named HTTP request headers. The values of other headers can be obtained with the req function . Using these variables may cause the header name to be added to the Vary header of the HTTP response, except where otherwise noted for the directive accepting the expression. The req_novary function may be used to circumvent this behavior. Name HTTP_ACCEPT HTTP_COOKIE HTTP_FORWARDED HTTP_HOST HTTP_PROXY_CONNECTION HTTP_REFERER HTTP_USER_AGENT Other request related variables Name Description REQUEST_METHOD The HTTP method of the incoming request (e.g.
GET ) REQUEST_SCHEME The scheme part of the request's URI REQUEST_URI The path part of the request's URI, excluding the query string. Note that this differs from the CGI environment variable of the same name, which includes the query string. DOCUMENT_URI Same as REQUEST_URI REQUEST_FILENAME The full local filesystem path to the file or script matching the request, if this has already been determined by the server at the time REQUEST_FILENAME is referenced.
Otherwise, such as when used in virtual host context, the same value as REQUEST_URI SCRIPT_FILENAME Same as REQUEST_FILENAME LAST_MODIFIED The date and time of last modification of the file in the format 20101231235959 , if this has already been determined by the server at the time LAST_MODIFIED is referenced. SCRIPT_USER The user name of the owner of the script. SCRIPT_GROUP The group name of the group of the script.
PATH_INFO The trailing path name information, see AcceptPathInfo QUERY_STRING The query string of the current request IS_SUBREQ " true " if the current request is a subrequest, " false " otherwise THE_REQUEST The complete request line (e.g., " GET /index.html HTTP/1.1 ") REMOTE_ADDR The IP address of the remote host REMOTE_PORT The port of the remote host (2.4.26 and later) REMOTE_HOST The host name of the remote host REMOTE_USER The name of the authenticated user, if any (not available during <If> ) REMOTE_IDENT The user name set by mod_ident SERVER_NAME The ServerName of the current vhost SERVER_PORT The server port of the current vhost, see ServerName SERVER_ADMIN The ServerAdmin of the current vhost SERVER_PROTOCOL The protocol used by the request DOCUMENT_ROOT The DocumentRoot of the current vhost AUTH_TYPE The configured AuthType (e.g.
" basic ") CONTENT_TYPE The content type of the response (not available during <If> ) HANDLER The name of the handler creating the response HTTP2 " on " if the request uses http/2, " off " otherwise HTTPS " on " if the request uses https, " off " otherwise IPV6 " on " if the connection uses IPv6, " off " otherwise REQUEST_STATUS The HTTP error status of the request (not available during <If> ) REQUEST_LOG_ID The error log id of the request (see ErrorLogFormat ) CONN_LOG_ID The error log id of the connection (see ErrorLogFormat ) CONN_REMOTE_ADDR The peer IP address of the connection (see the mod_remoteip module) CONTEXT_PREFIX CONTEXT_DOCUMENT_ROOT Misc variables Name Description TIME_YEAR The current year (e.g.
2010 ) TIME_MON The current month ( 01 , ..., 12 ) TIME_DAY The current day of the month ( 01 , ...) TIME_HOUR The hour part of the current time ( 00 , ..., 23 ) TIME_MIN The minute part of the current time TIME_SEC The second part of the current time TIME_WDAY The day of the week (starting with 0 for Sunday) TIME The date and time in the format 20101231235959 SERVER_SOFTWARE The server version string API_VERSION The date of the API version (module magic number) Some modules register additional variables, see e.g. mod_ssl .
Binary operators ¶ With the exception of some built-in comparison operators, binary operators have the form " -[a-zA-Z][a-zA-Z0-9_]+ ", i.e. a minus and at least two characters. The name is not case sensitive. Modules may register additional binary operators. Comparison operators Name Alternative Description == = String equality != String inequality < String less than <= String less than or equal > String greater than >= String greater than or equal =~ String matches the regular expression !~ String does not match the regular expression -eq eq Integer equality -ne ne Integer inequality -lt lt Integer less than -le le Integer less than or equal -gt gt Integer greater than -ge ge Integer greater than or equal Other binary operators Name Description -ipmatch IP address matches address/netmask -strmatch left string matches pattern given by right string (containing wildcards *, ?, []) -strcmatch same as -strmatch , but case insensitive -fnmatch same a
The rest of this page is on the live site.