title: Apache 2.4: Can I use variables for conditionals in requests?
body: <h1>tl;dr</h1>
  <p>In NGINX, you can define variables and evaluate them in each request. I'm not possible to reproduce this in Apache v2.4. <strong>Can I use variables for conditionals in requests at all?</strong></p>
  <h1>What I want</h1>
  <p><code>${docroot}/dev/api.php</code> contains an API, which should never be reached by direct access, but by location <code>/api</code> only.</p>
  <ol>
  <li>user visits <code>example.org/dev/api.php</code> and get gets an error 404 or &quot;Authorization required&quot;</li>
  <li>user visits <code>example.org./api/endpoint</code>, which falls back to /dev/api.php internally.</li>
  </ol>
  <p>In NGINX, I can use a variable for this. If the user visits the location, the variable is TRUE, otherwise (e.g. direct access) it's false and he get's the error.</p>
  <h1>Code</h1>
  <pre><code>&lt;VirtualHost *:8443&gt;
      Define docroot /var/www/html/test
      Define fromAPI false # default is: no access
   
      ServerName    shop.example.org
      ServerAdmin   admin@example.org
      DocumentRoot  ${docroot}
      Protocols h2 http/1.1
   
      # that's the location of the API (there is no directory named &quot;api&quot;)
      &lt;Location /api&gt;
          AllowOverride None
          Define fromAPI true # user has access
          FallbackResource /dev/api.php
      &lt;/Location&gt;
   
      # The API code is living here.
      # When user visits it &quot;${fromAPI} == false&quot;, it should end up in error 404.
      # When API visits it &quot;${fromAPI} == true&quot;, the access should be granted.
      &lt;Directory ${docroot}/dev&gt;
          # &lt;If &quot;-T env('fromAPI')&quot;&gt;
          # &lt;If &quot;-T env('fromAPI')&quot;&gt;
          # &lt;If &quot;${fromAPI}&quot;&gt;
          # &lt;If &quot;-T '${fromAPI}'&quot;&gt;
              Redirect 404 /dev/
          &lt;/If&gt;
      &lt;/Directory&gt;
    
      SSLEngine on
      SSLProtocol -all +TLSv1.2 
      SSLCertificateFile    /etc/letsencrypt/live/example.org/fullchain.pem
      SSLCertificateKeyFile /etc/letsencrypt/live/example.org/privkey.pem
   
      # HTTP Strict Transport Security (mod_headers is required) (31536000 seconds)
      Header always set Strict-Transport-Security &quot;max-age=31536000; includeSubDomains; preload&quot;
  </code></pre>