Determine apache version in apache configuration?

tl; dr: How to do the following in a .conf or .htaccess file:

<IfApache22> # Do A </IfApache22> <IfApache24> # Do B </IfApache24> 

Longer question:

With Apache 2.4, the old Order becomes obsolete in favor of Require .

In my .htaccess files I have

 <FilesMatch "\.(long|list|file|types)$"> Order allow,deny </FilesMatch> 

which means that Apache does not start unless I enable access_compat . While this creates a useful solution, I want a solution that works with both syntaxes, as config will propagate to a large number of servers. The question is how can I determine the current version of Apache and apply the correct directive.

I intend to use the file for the framework, which is distributed and used by many people, and I can not control / guarantee that they have or not any specific server settings, so I would like the file to be 2.2 / 2.4 "agnostic" .

+19
apache .htaccess
May 22 '12 at 17:42
source share
5 answers

The hack that I used.

 # Apache 2.2 <IfModule !mod_authz_core.c> Satisfy Any </IfModule> # Apache 2.4 <IfModule mod_authz_core.c> Require all granted </IfModule> 
+27
Feb 26 '13 at 5:09
source share

Assuming you have mod_version installed (many distributions send it by default), you can do the following:

 <IfVersion >= 2.4> # Require ... </IfVersion> <IfVersion < 2.4> # Order ... # Deny ... # Allow ... </IfVersion> 
+14
Nov 22 '13 at 1:14
source share

You can run different versions of Apache on the same host. Q: What is wrong with separate configuration files in separate directories? I honestly believe that perhaps the cleanest approach ...

However, Apache.conf files allow <IfDefine> , which you can specify at runtime with "-D":

http://httpd.apache.org/docs/2.0/mod/core.html#ifdefine

+2
May 22 '12 at 17:47
source share

You can get around the need to know with mod_rewrite for your access control:

 RewriteEngine On RewriteCond %{REQUEST_URI} !\.(long|list|file|types)$ RewriteRule .* - [F,L] 
+1
Nov 22 '13 at 1:00
source share

I ran into this problem because FallbackResource is not in early versions of Apache, and often smart hosting companies remove mod_rewrite when they have a version of Apache with FallbackResource. I use the following .htaccess when I want to put library code 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 versions / installations of Apache where this fails, but if mod_rewrite exists, use it, and if not, hope that FallbackResource is there.

+1
Aug 27 '16 at 13:45
source share



All Articles