Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have two proxypass rules on my web host, one that points to a local varnish instance for caching purposes, which I want ProxyPreserveHost enabled for, and another that points to a third party hosted site, which I want ProxyPreserveHost disabled for. Is there anyway I can do this on a per rule/pass basis?

share|improve this question

Under Apache 2.2, no - the ProxyPreserveHost directive is only valid in the server config or virtual host contexts; you'd need the different ProxyPass statements to be in different virtual hosts.

In Apache 2.4, yes - the directory context has been added for the directive, so you can now do something such as:

<Location /to-varnish/>
    ProxyPreserveHost On
<Location /to-third-party/>
    ProxyPreserveHost Off
share|improve this answer
ah, that makes sense. thanks. – 580farm Dec 4 '12 at 22:09

You can with help of RequestHeader

ProxyPreserveHost On
<LocationMatch third-party-pattern>
   RequestHeader  set  Host  third-party-vhost-name
   ProxyPassMatch  http://third-party-server
<LocationMatch varnish-pattern>
   ProxyPassMatch  http://varnish-server
share|improve this answer

I'm unable to upvote Sorin's response...

In our local situation running Apache 2.2, and the primary app requires proxypreservehost (CQ/AEM author) to login, but a partner we proxy to requires their host in the host header.

We don't need to do this with regex though, a regular <Location...> works fine.

From documentation (

The directive limits the scope of the enclosed directives by URL.

This solution works for us:

  <Location /[path]/ >
    RequestHeader set Host [thirdparty]
  RewriteRule ^/[path]/(.*) https://[thirdparty]/$1 [P,NC,L]

This sets the host header for this request to the partner's hostname.

With that in place, we can continue to login to CQ/AEM author AND proxy to the partner service using their expected host header.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.