I'm trying to add a conditional statement using Apache's If directive in my .htaccess file.
I have referenced this page http://httpd.apache.org/docs/trunk/mod/core.html#if but it doesn't elaborate much / give many examples. Two incomplete examples it gives are:
<If %{REQUEST_METHOD} IN GET,HEAD,OPTIONS>
and
<If "$req{Host} = ''">
So I've tried to add this to my .htaccess file:
<If %{SERVER_PORT} IN GET,HEAD,OPTIONS> #nothing here yet </If>
But I keep getting Error 500 when I try and load the page. This is on my local install, and it was working fine previously (or if I remove that code). I believe I have AllowOverride All
set up globally, and the context for the If directive should let it be present in .htaccess ("Context: server config, virtual host, directory, .htaccess").
Can someone give me some examples of how to properly use the <If> directive, or some guidance as to why it is not working for me?
Thanks!
The
<If>
directive is only available in Apache 2.4+ and not 2.2 or earlier.http://httpd.apache.org/docs/2.4/mod/core.html#if
Documentation not present in 2.2:
http://httpd.apache.org/docs/2.2/mod/core.html#if
<If>
is only available in Apache 2.4+, so firstly make sure that you have that version.Examples
Alternatives to
<If>
There are a few other solutions for doing conditional statements in Apache 2.2 if you're still stuck with that.
You can set environment variables via:
SetEnvIf
RewriteMatch
Then you can perform conditional statements using
Example: