Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

209
Views
Use Require in both VirtualHost and .htaccess

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?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

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.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!