title: How to I get control of the Cache-Control header with Wordpress on Apache?
body: <p>This is driving me absolutely nuts. We're running Wordpress on Apache (we're new to this stack, if that's not obvious). Specifically this is a Bitnami AMI. Since we're pretty much 100% on AWS, I wanted to use Cloudfront dynamic content caching in front of the Wordpress site. I've read tons of docs/posts about how to use W3 Total Cache (or similar) to make this work. But all I really want to do is get a grip on the Cache-Control header so I can get Cloudfront to work the way it's supposed to.</p>
  
  <p>Currently, I have modified functions.php to include code (based on another post here) which is supposed to modify the header.</p>
  
  <pre><code>function varnish_safe_http_headers() {
      session_cache_limiter('');
      header_remove("Cache-Control");
      header("Cache-Control: public, max-age=60");
    if( !session_id() )
    {
      session_start();
    }
  }
  add_action( 'template_redirect', 'varnish_safe_http_headers' );
  </code></pre>
  
  <p>Unfortunately, what I wind up with is TWO headers.</p>
  
  <pre><code>Cache-Control:public, max-age=60
  Cache-Control:max-age=0, no-cache
  </code></pre>
  
  <p>The first header is mine. The second header is coming from some other location in the stack that I can't seem to find/configure. I've searched the entire contents of the Wordpress directory for any string that I can think of that would help me find code that does this. </p>
  
  <p>I've also tried changing the "hook" in the add_action call to any number of values, working my way from "send_headers" down through. The only result is that the two cache-control headers change order. I cannot, so far, remove/overwrite the "max-age=0, no-cache" value.</p>
  
  <p>I've also tried modifying .htaccess, the Bitnami-specific htaccess.conf file, etc, etc.</p>
  
  <p><strong>EDIT</strong>: After reading <a href="http://www.informit.com/articles/article.aspx?p=705689&amp;seqNum=7" rel="nofollow">here</a>, it seems that the second header must be caused somewhere within Wordpress/PHP. This document makes it appear that the "handler" (in this case PHP) gets the last word on response processing. Once that phase is complete, there is only sending the response to the client and logging.</p>
  
  <p><strong>EDIT 2</strong>: I added a foo.php file to the root of the site. It calls no Wordpress functions at all. Both Cache-Control headers still appear. Here are the entire contents of the file.</p>
  
  <pre><code>&lt;?php
  header("Cache-Control: public, max-age=60");
  ?&gt;
  </code></pre>