I want to have GeoIP checking in VirtualHost and on success to have the .htaccess file of the webpage to be processed, which also has some Require directives set (for its files).
I use macros and environment vars for dynamic configs, so currently my vhost config looks like this:
<VirtualHost ${myIP4}:443>
...
<Directory "/srv/www/$domain/htdocs">
MaxMindDBEnable On
MaxMindDBFile COUNTRY_DB /var/lib/GeoIP/GeoLite2-Country.mmdb
MaxMindDBEnv MM_COUNTRY_CODE COUNTRY_DB/country/iso_code
SetEnvIf MM_COUNTRY_CODE "^$countries" PassCountry
AllowOverride None
Require all denied
Require env PassCountry
</Directory>
This works fine when access for $countries should be revoked, as the Require all denied wins.
But when it's a valid country code, the .htaccess file should get executed, for which I would need an AllowOverride All here.
I tried several ways like
<If "reqenv('PassCountry') == 1">
AllowOverride All
</If>
but the if clause seems not to be evaluated correctly.
But that's not the only problem. Also when adding same in the else tree (for testing purposes)
<Else>
AllowOverride All
</Else>
it is not recognized although it says that it can be used within if clauses.
Only directives that support the directory context can be used within this configuration section.
see https://httpd.apache.org/docs/2.4/en/mod/core.html#if
So how could I solve my problem?
Solved it now by using mod_rewrite like that:
MaxMindDBEnable On
MaxMindDBFile COUNTRY_DB /var/lib/GeoIP/GeoLite2-Country.mmdb
MaxMindDBEnv MM_COUNTRY_CODE COUNTRY_DB/country/iso_code
SetEnvIf MM_COUNTRY_CODE "^$countries" PassCountry=1
RewriteEngine on
RewriteCond %{ENV:PassCountry} !1
# allow showing error documents (maybe required to be adopted when not using defaults)
RewriteRule !(^/error/) "-" [F]
But this does not work inside the <Directory> directive, so move it out from there.