I was trying to get my Apache Server (v2.4.7) to respond to an If-Modified-Since header sent by browsers and spiders like Google. I found this on a recommendation on Google Webmaster. I never knew about this until yesterday, nor did I know Apache was not responding to that header and therefore not sending back a Last-Modified header to the browser or spider.

I also then noticed that every request from my server was sending back pragma: nocache

After a lot of reading and fiddling I actually got it working on my main site.

This was only after discovering that a setting in php.ini for php-fpm called session.cache_limiter which was set to nocache so I set it to session.cache_limiter = public

Rebooted the server and voila, that site was giving the correct headers and it passed on various If-Modified-Since header testers.

Now the problem .... on all my other 15 wordpress sites they are still sending the pragma:nocache header and none of the other cache headers that are showing on the main site.

All sites have the exact same config in their apache .conf files All sites have the exact same config in their .htaccess All sites are running Wordpress

I have tried in the other sites to set and unset headers in the apache .conf files but they are simply just being ignored.

For the life of me I am missing something and I do not know where or what, have been going through .conf and .htaccess and php.ini files all day long.

Something is interfering with the headers and I do not know what.

These are my loaded Apache modules if it helps

Loaded Modules:
 core_module (static)
 so_module (static)
 watchdog_module (static)
 http_module (static)
 log_config_module (static)
 logio_module (static)
 version_module (static)
 unixd_module (static)
 access_compat_module (shared)
 actions_module (shared)
 alias_module (shared)
 auth_basic_module (shared)
 authn_core_module (shared)
 authn_file_module (shared)
 authz_core_module (shared)
 authz_host_module (shared)
 authz_user_module (shared)
 autoindex_module (shared)
 deflate_module (shared)
 dir_module (shared)
 env_module (shared)
 evasive20_module (shared)
 expires_module (shared)
 fastcgi_module (shared)
 filter_module (shared)
 headers_module (shared)
 mime_module (shared)
 mpm_event_module (shared)
 negotiation_module (shared)
 pagespeed_module (shared)
 rewrite_module (shared)
 setenvif_module (shared)
 socache_shmcb_module (shared)
 spamhaus_module (shared)
 ssl_module (shared)
 status_module (shared)

and this is the output of -V

Server version: Apache/2.4.7 (Ubuntu)
Server built:   Jan 14 2016 17:45:23
Server's Module Magic Number: 20120211:27
Server loaded:  APR 1.5.1-dev, APR-UTIL 1.5.3
Compiled using: APR 1.5.1-dev, APR-UTIL 1.5.3
Architecture:   64-bit
Server MPM:     event
  threaded:     yes (fixed thread count)
    forked:     yes (variable process count)
Server compiled with....
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D HTTPD_ROOT="/etc/apache2"
 -D SUEXEC_BIN="/usr/lib/apache2/suexec"
 -D DEFAULT_PIDLOG="/var/run/apache2.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="mime.types"
 -D SERVER_CONFIG_FILE="apache2.conf"

I am truly stumped right now but I haven't given up looking just yet, hoping someone can shed light on what may be interfering with / overriding the headers being sent.

To add to my confusion now ... the site where it is sending the Last-Modified header it's wrong on every page

Last-Modified:Tue, 02 Dec 2014 11:21:14 GMT

If I look into individual resources inside the page they have the correct Last-Modified

like my style.css shows Last-Modified:Thu, 02 Jun 2016 09:41:24 GMT

So it is giving Last-Modified responses but on the top level, ie. the page itself it has a date far in the past.

On the web site where it is not sending the Last-Modified header, it actually is but it is sending them only for resources in the page like css, jpg, etc etc but NOT for the page itself.

So .... 1 problem turns into 2.

Where the hell is this happening and where is is getting that date from?

Is this an Apache bug? A Wordpress bug?

I have even gone through disabling plugins on the wordpress sites not sending the Last-Modified header for the page but that has not effect.

I still think this is happening inside Apache or PHP somewhere.


I hope this helps any other person running Wordpress sites on Apache, I found the problem and it is nothing to do with Apache at all.

The problem is that Wordpress strips out the Etag, Last-Modified, Expires and Cache-Control headers from all pages and posts.

But for those wanting actual control over what can be cached and not cached that control is just removed.

Thanks go out to an individual who wrote such a plugin for Wordpress and it just works out of the box. It can also be further customized by adding functions, filters and hooks to your theme's functions.php file.

The plugin can be obtained from: https://wordpress.org/plugins/add-headers/

Details and Thorough Documentation for the plugin is at:

http://www.codetrax.org/projects/wp-add-headers/wiki/Configuration and http://www.codetrax.org/projects/wp-add-headers/wiki/Filter_and_Action_Hooks

So hopefully this will save someone else from losing their mind like I nearly did thinking there was something going on with Apache meanwhile not-so-innocent Wordpress was doing this.

I know finally have full control over my headers again and through this plugin's hooks and filters I can customize the cache times, even on individual pages and especially on things like a shopping cart system which I can set to zero seconds caching. So simple :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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