Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

217
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda