Trying to be clever and allow access depending on an environment variable. It doesn't seem to work (no errors, the expression is always false).

What I tried:

<VirtualHost *:80>


  <Directory /var/www/html>
    Options       Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order         allow,deny

    <If "reqenv('ENVIRONMENT_STATE') == 'dev'">
      allow from 1.22.333.0/24
      deny from all
      allow from all

Expected behavior:

If ENVIRONMENT_STATE is set to 'dev', then restrict all access except from the mentioned IP.




I would use the .htaccess file for IP restrictions. The reasons being:

  • You can source control it.
  • No server restart required when adding or removing IP addresses.
  • If you accidentally lock yourself out you can always FTP in and edit the file to restore access.

See this question for an example.

  • Thanks for taking the time to respond, but I'm not sure how this answered the question regarding the deny depending on the ENVIRONMENT_STATE variable value? Could you please elaborate? – superhero Oct 14 '15 at 15:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.