I would like to add a rule in .htaccess that "Does something" (actually enable a httpauth user restriction) depending on the domain name.
I thought I had it and did:
<IfModule mod_setenvif.c>
SetEnvIf Host "staging\.(.*)\.ch" HTTPAUTHPROTECT=true
<IfDefine HTTPAUTHPROTECT>
# Do something
# For testing, I used the following line:
# SetEnvIf Host "staging\.(.*)\.ch" CONDITIONMATCHED=conditionmatched
</IfDefine>
</IfModule>
On a server that runs with Litespeed, I thought this was working. Maybe I was wrong and the <IfDefine HTTPAUTHPROTECT>
part returns true all the time. On another server with Apache (2.4.54), it keeps returning false no matter what the ENV var is set to.
I read on SO that on Apache,
IfDefine
doesn't work that way anyway. Is that true?So is there a way to make such a condition?
PS: I'm not referring to a rewrite rule. The code I want to execute conditionally is:
AuthType Basic
AuthName "Login"
AuthUserFile "/path/to/.htpasswd"
Require valid-user