title: Apache URL rewrite before Proxy
body: <p>I have apache set up as a proxy to my application that needs to run on a specific port, this works fine with virtual host. Now I need to add another directive, I need to remove /ex/ from any incoming request and pass the rewritten url it to the proxy. </p>
  
  <p>I can't seem to get both to work, either apache is able to rewrite the url but then fails to proxy and tries to serve the request itself, or it proxies correctly without removing /ex/ and my application routing fails because it's looking for /ex/.</p>
  
  <p>Here's the proxy config that works (without the rewrite).
  How can I remove /ex/ before passing it to the proxy ? Apparently apache can't [P,R] at the same time, PT simply forwards as is.</p>
  
  <pre><code>&lt;VirtualHost *:82&gt;
    ServerName xxx
    ServerAlias xxx
  
    DocumentRoot /opt/xxx
  
    RewriteEngine On
  
    # neither of these works, simply proxies as is to my application, routing fails
    # RewriteRule ^ex/(.*) /$1 [L,R]
    # RewriteRule ^/ex$ / [L,PT]
  
    RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
    RewriteRule ^/(.*)$ http://127.0.0.1:11110%{REQUEST_URI} [P,QSA,L]
  
    ProxyPass / http://127.0.0.1:11110/
    ProxyPassReverse / http://127.0.0.1:11110/
    ProxyPreserveHost on
  
    # this doesn't work either
    # ProxyPass /ex http://127.0.0.1:11110/
  
  &lt;/VirtualHost&gt;
  </code></pre>