tl;dr: How do I do the following in a .conf or .htaccess file:
# Do A
# Do B
&
You can run different versions of Apache on the same host. Q: What's wrong with separate config files in separate directories? I honestly believe that's probably the cleanest approach...
Nevertheless, Apache .conf files allow an <IfDefine>
, which you can specify at runtime with "-D":
http://httpd.apache.org/docs/2.0/mod/core.html#ifdefine
Assuming you have mod_version installed (many distributions ship it by default) you can do the following:
<IfVersion >= 2.4>
# Require ...
</IfVersion>
<IfVersion < 2.4>
# Order ...
# Deny ...
# Allow ...
</IfVersion>
I ran into this problem because FallbackResource is not in early versions of Apache and often clever hosting companies remove mod_rewrite once they have a version of Apache with FallbackResource. I use the following .htaccess when I want to put library code up that adapts to its environment:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^ - [E=protossl]
RewriteCond %{HTTPS} on
RewriteRule ^ - [E=protossl:s]
RewriteRule "(^|/)\." - [F]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^ index.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
FallbackResource index.php
</IfModule>
Now of course there are some Apache versions / setups where this fails - but if mod_rewrite is there, use it and if not, hope that FallbackResource is there.
You could bypass the need to know by using mod_rewrite for your access control:
RewriteEngine On
RewriteCond %{REQUEST_URI} !\.(long|list|file|types)$
RewriteRule .* - [F,L]
A hack that I have used.
# Apache 2.2
<IfModule !mod_authz_core.c>
Satisfy Any
</IfModule>
# Apache 2.4
<IfModule mod_authz_core.c>
Require all granted
</IfModule>