Skip to content

Conditionals

DirectiveSyntax
<If><If "expression">
<ElseIf><ElseIf "expression">
<Else><Else>
OperatorDescriptionExample
==String equality"%{REQUEST_URI}" == "/admin"
!=String inequality"%{HTTPS}" != "on"
=~Regex match"%{REQUEST_URI}" =~ /\.php$/
!~Regex not match"%{HTTP_USER_AGENT}" !~ /bot/i
-fFile exists-f "%{REQUEST_FILENAME}"
-dDirectory exists-d "%{REQUEST_FILENAME}"
-sFile exists and not empty-s "%{REQUEST_FILENAME}"
-lIs symlink-l "%{REQUEST_FILENAME}"
-ipmatchIP/CIDR match"-ipmatch" "192.168.0.0/16"
&&Logical AND
||Logical OR
!Logical NOT
<If "%{HTTPS} == 'on'">
Header set Strict-Transport-Security "max-age=31536000"
</If>
<If "-ipmatch '10.0.0.0/8'">
Require all granted
</If>
<Else>
Require valid-user
</Else>
<If "%{REQUEST_METHOD} == 'OPTIONS'">
Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Methods "GET, POST, OPTIONS"
</If>