title: Apache LocationMatch Regex
body: <p><strong>My Problem</strong></p>
  
  <p>I need to have Apache HTTP Server (v2.4.10) proxy requests to Tomcat for dynamic applications, which not only do not match the path in Tomcat, but are also have similar paths to one another. For example:</p>
  
  <p><code>/products/&lt;category&gt;/&lt;sub-category&gt;/&lt;sub-sub-category&gt;/&lt;product-id&gt;.html</code> proxy to: <code>http://mycluster/pf/&lt;product-id&gt;.html</code></p>
  
  <p>...and also...</p>
  
  <p><code>/products/&lt;category&gt;/&lt;sub-category&gt;/&lt;sub-sub-category&gt;/&lt;anything-not-ending-in-html&gt;</code> proxy to: <code>http://mycluster/search/&lt;anything-not-ending-in-html&gt;</code></p>
  
  <p><strong>My Attempts</strong></p>
  
  <p>I'm trying to use LocationMatch regex to handle this, but am not being fully successful. The following LocationMatch regex works on its own (proxy the <code>*.html</code> request to <code>&lt;tomcat&gt;/pf/*.html</code>):</p>
  
  <pre><code>&lt;LocationMatch ^/products/(?&lt;cat&gt;.+)/(?&lt;subcat&gt;.+)/(?&lt;subsubcat&gt;.+)/(?&lt;partnum&gt;.+).html&gt;
  ProxyPass balancer://mycluster/pf/%{env:MATCH_PARTNUM}.html
  ProxyPassReverse balancer://mycluster/pf/%{env:MATCH_PARTNUM}.html
  &lt;/LocationMatch&gt;
  </code></pre>
  
  <p>This passes URLs using the following example path: <code>/products/aaa/bbb/ccc/ddd3456.html</code> (which is correct)</p>
  
  <p>However, when I also enable the regex below:</p>
  
  <pre><code>&lt;LocationMatch ^(?!.*\.html$)/products/(?&lt;cat&gt;.+)/(?&lt;subcat&gt;.+)/(?&lt;subsubcat&gt;.+)((/?)|(./*))$&gt;
  ProxyPass balancer://mycluster/search/
  ProxyPassReverse balancer://mycluster/search/
  &lt;/LocationMatch&gt;
  </code></pre>
  
  <p>Trying to access <code>/products/aaa/bbb/ccc/</code> results in the 404 page. 
  Here I'm expecting any requests to "/products/aaa/bbb/ccc/" that do NOT end in .html to be passed to /search/ (including any subsequent path info to be included: eg .../search/compare )</p>
  
  <p><strong>My Question</strong></p>
  
  <p>I can't quite figure it out what is wrong. According to <a href="http://rubular.com" rel="noreferrer">Rubular</a> the supplied regex is correct:</p>
  
  <ul>
  <li><a href="http://rubular.com/r/AjWPTUP1I6" rel="noreferrer">Search Regex</a></li>
  <li><a href="http://rubular.com/r/mmDF7r0L3I" rel="noreferrer">Product Regex</a></li>
  </ul>
  
  <p>What am I missing here?</p>
  
  <p>I'd appreciate any advice on resolving this!</p>