title: Apache2.4+ htaccess rewrite ignored when using <If> directives
body: <p>I'm getting a really weird bug that I'm hoping someone would be able to tell me if I'm doing anything wrong here.</p>
  
  <p><strong>The code that is working</strong></p>
  
  <p>I have a small piece of .htaccess code which is working great. It checks if an HTML file exists and if not tries to load a PHP file instead. Here is that code..</p>
  
  <pre><code>&lt;IfModule mod_rewrite.c&gt;
      RewriteEngine On
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteRule ^(.*)\.html$ $1.php [L]
  &lt;/IfModule&gt;
  </code></pre>
  
  <p><strong>The code that is a problem</strong></p>
  
  <p>When I introduce an <a href="http://httpd.apache.org/docs/2.4/mod/core.html#if" rel="nofollow noreferrer">If directive</a> this code gets ignored, regardless of if it's before or after the .</p>
  
  <pre><code># We go to http://site.local/index.html in our browser
  &lt;IfModule mod_rewrite.c&gt;
      RewriteEngine On
  
      # Commenting out the if and keeping the rewrite rule inside works
      &lt;If "(req('Host') == 'site.local')"&gt;
          # Commenting out everything inside and keeping the if statement works too
          # This rule below is to demonstrate that even though this rule won't
          # match anything it has an affect on the rule outside the if
          RewriteCond %{HTTP_HOST} ^RANDOMRULENOTMATCHED\.
          RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
      &lt;/If&gt;
  
      # this rule gets ignored by the above, you can also put these lines above the if, they'll still be ignored
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteRule ^(.*)\.html$ $1.php [L]
  &lt;/IfModule&gt; 
  </code></pre>
  
  <p>So my question is, why does my rewrite condition get ignored when using an If directive in the .htaccess file?</p>
  
  <p>As a sidenote I know that I could fix this by using more RewriteCond, however my aim is to use the If directive feature so please could the answers focus on keeping the If directive in the code.</p>