title: Apache htaccess rewrite dynamic rewritebase
body: <p>I struggle with htaccess for production and local environment.
  My production url is like: <a href="https://example.com/folder/file.php" rel="nofollow noreferrer">https://example.com/folder/file.php</a>
  Local I use: <a href="https://example.dev.local/app/folder/file.php" rel="nofollow noreferrer">https://example.dev.local/app/folder/file.php</a></p>
  
  <p>As you can see my local environment is using app which is a subfolder.
  I want to prevent to set RewriteBase /app/</p>
  
  <p>So affter searching I found answers like:</p>
  
  <pre><code>RewriteCond %{REQUEST_URI}::$1 ^(.*?/)(.*)::\2$
  RewriteRule ^(.*)$ - [E=BASE:%1]
  </code></pre>
  
  <p>However I can get it work for my local enviroment.
  My htaccess is:</p>
  
  <pre><code>Options -Indexes
  
  RewriteEngine On
  
  # Redirect if not https
  RewriteCond %{HTTPS} off
  RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
  
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  
  # Urls ends with html
  RewriteRule ^(.*).html$ index.php?rt=$1&amp;%{QUERY_STRING} [L,QSA]
  
  # requests which are not static sources will be handled for the admin environment
  RewriteCond %{REQUEST_URI} !^admin_cms/\.*\.(jpe?g|css|js|gif|png|woff2?|ttf|ico)$ [NC]
  RewriteRule ^admin_cms/?(.*)$ admin.php?rt=$1&amp;%{QUERY_STRING} [L,QSA]
  </code></pre>
  
  <p>an URL like:
  <a href="https://example.dev.local/app/admin_cms/file.php" rel="nofollow noreferrer">https://example.dev.local/app/admin_cms/file.php</a> should get matched for the second rule, but match only when I navigate to an url without app.</p>
  
  <p>So my question is, how do I get it work that both (prod / local) work with the same htaccess?</p>
  
  <p>Ps. I tried also <code>RewriteRule ^%{ENV:BASE}/admin_cms/?(.*)$ admin.php?rt=$1&amp;%{QUERY_STRING} [L,QSA]</code></p>