title: How to write regex for apache ProxyPassMatch to reverse proxy API calls
body: <p>I have an angular 4 web application which is hosted on apache 2.4. The application makes use of an API written in nodejs javascript running over express. Both the website and the API service are running on the same machine but on different ports. The website is on port 80 and the API service is listening on port 9000.</p>
  
  <p>I would like to set up apache to do reverse proxy for all the API calls.</p>
  
  <p>For example, any url that contains /api/ I want it rewritten by apache to point to the API url:port. If I use ProxyPass like the following lines, the redirect works fine:</p>
  
  <pre><code>ProxyPass        "/api/V1/systeminfo" "http://localhost:9000/api/V1/systeminfo"
  ProxyPassReverse "/api/V1/systeminfo" "http://localhost:9000/api/V1/systeminfo"
  </code></pre>
  
  <p>What I do not know how to do, is to use the ProxyPassMatch directive and create a regular expression so that any url that contains /api/ is redirected to <a href="http://localhost:9000/api/" rel="nofollow noreferrer">http://localhost:9000/api/</a>.....</p>
  
  <p>I tried the following but it does not work:</p>
  
  <pre><code>ProxyPassMatch    "^/api.*$" "http://localhost:9000/$1"
  ProxyPassReverse  "^/api.*$" "http://localhost:9000/$1"
  </code></pre>
  
  <p>Neither does the following:</p>
  
  <pre><code>ProxyPassMatch    "^/.*?/api.*?/v[0-9]+/(.*)$" "http://localhost:9000/$1"
  ProxyPassReverse  "^/.*?/api.*?/v[0-9]+/(.*)$" "http://localhost:9000/$1"
  </code></pre>
  
  <p>Any help would be appreciated. My regex skills are lacking!</p>
  
  <p>Note: obviously 'localhost' can be an IP address or a domain, I am using it in the example for simplicity.</p>
  
  <p>Many thanks!</p>
  
  <p>Edit: I corrected the first example to use .* instead of just * as per Alex's comment.</p>