title: Apache Server Reverse Proxy with ProxyPreserveHost On results in 404
body: <p>I'm hoping someone here with experience with <code>Apache</code> can help me out.  I have an internal server, that I'm fronting with <code>Apache Reverse Proxy</code>.  i.e.</p>
  
  <ul>
  <li><strong>Apache Server:</strong> <a href="https://www.myexternalserver.com" rel="nofollow noreferrer">https://www.myexternalserver.com</a></li>
  <li><strong>Internal Server:</strong> <a href="https://www.myinternalserver.com" rel="nofollow noreferrer">https://www.myinternalserver.com</a></li>
  </ul>
  
  <h3>Apache Settings</h3>
  
  <pre><code>&lt;Proxy *&gt;
          Order allow,deny
          Allow from all
  &lt;/Proxy&gt;
  
  RewriteEngine On
  RewriteCond %{REQUEST_METHOD} ^TRACE
  RewriteRule .* - [F]
  
  ProxyVia Off
  ProxyRequests Off
  ProxyPreserveHost On
  
  SSLProxyEngine On
  SSLProxyCheckPeerCN Off
  SSLProxyCheckPeerExpire Off
  SSLProxyCheckPeerName Off
  SSLProxyVerify none
  
  ProxyPass               /internal   https://www.myinternalserver.com
  ProxyPassReverse        /internal https://www.myinternalserver.com
  
  &lt;Location /&gt;
          Allow from all
  #       Require all granted
  &lt;/Location&gt;
  </code></pre>
  
  <p>The problem I'm having is such:</p>
  
  <ul>
  <li>The internal application in code uses <code>getRequest().getServerName()</code> to get the url.  If I turn off <code>ProxyPreserveHost</code> and set it to <code>Off</code>, then the internal application ends up being the url that is returned.  This is not what I want since this internal application url is not accessible to the public.  </li>
  <li>From what I've read, <code>ProxyPreserveHost</code> needs to be <code>On</code> so that the <code>Apache Reverse Proxy</code> can pass it's url to the underlying internal applications.  When I do this however, I get a 404.  I understand that what is probably happening is that the internal server is using the external domain to find its application and thus cannot find it.  I'm not sure how to get around this.  Btw, the internal application is hosted on <code>PCF</code>.  </li>
  </ul>
  
  <p>I would appreciate it if someone could help me out.  </p>
  
  <p>Thanks!</p>