I had the following caching problem on a client's site running Drupal 5. I'm pretty sure this issue still exists in Drupal 6 too but haven't tested it yet.

Pages were "cached for two weeks" (because of the mod_rewrite in .htaccess) on client side.

The client runs Apache 1.3.

I found a solution in my case via http://drupal.org/node/213078 but since this was in a deprecated forum, and never got into core, I tought it was good to mention this in the issue queue.

PROBLEM

With Drupal's default .htaccess file:

<IfModule mod_expires.c>
  # Enable expirations.
  ExpiresActive On
  # Cache all files for 2 weeks after access (A).
  ExpiresDefault A1209600
  # Do not cache dynamically generated pages.
  ExpiresByType text/html A1
</IfModule>

I get the following headers:

HTTP/1.x 200 OK
Date: Thu, 09 Oct 2008 22:18:08 GMT
Server: Apache/1.3.33 (Debian GNU/Linux) FrontPage/5.0.2.2635 mod_ssl/2.8.22 OpenSSL/0.9.7e
Cache-Control: no-cache, must-revalidate, max-age=1209600
Expires: Mon, 26 Jul 1997 05:00:00 GMT, Thu, 23 Oct 2008 22:18:08 GMT
X-Powered-By: PHP/5.2.5-0.dotdeb.0
Keep-Alive: timeout=15, max=95
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/css

SOLUTION

When I disable mod_rewrite for PHP:

<IfModule mod_expires.c>
  # Enable expirations.
  ExpiresActive On
  # Cache all files for 2 weeks after access (A).
  ExpiresDefault A1209600
  # Do not cache dynamically generated pages.
  ExpiresByType text/html A1

 <FilesMatch "\.(php)$">
 ExpiresActive Off
 </FilesMatch>

</IfModule>

I get the following correct headers:

HTTP/1.x 200 OK
Date: Thu, 09 Oct 2008 22:17:34 GMT
Server: Apache/1.3.33 (Debian GNU/Linux) FrontPage/5.0.2.2635 mod_ssl/2.8.22 OpenSSL/0.9.7e
Cache-Control: must-revalidate
Content-Encoding: gzip
Etag: "651e2d539da48f303bbb3b37717ca3f8"
Expires: Sun, 19 Nov 1978 05:00:00 GMT
X-Powered-By: PHP/5.2.5-0.dotdeb.0
Last-Modified: Thu, 09 Oct 2008 22:15:54 GMT
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html; charset=utf-8

Comments

drumm’s picture

Version: 5.x-dev » 7.x-dev

This code in .htaccess is the same in the development version.

davyvdb’s picture

I just checked and the code in drupal_page_cache_header is still the same too except for the protocol of the 304 header.

header($_SERVER['SERVER_PROTOCOL'] . ' 304 Not Modified');

Anonymous’s picture

I have also had this problem, with Drupal 6.10, on two separate shared hosting sites. I don't know what the root cause is, but it would seem that the line "ExpiresByType text/html A1" is for some reason not getting actioned.

The solution by the original poster works for me - please include this in the standard distribution, unless someone more knowledgeable than me can fix the root cause.

Regards, Tony

bismigalis’s picture

I had this problem too. I discovered (from internet) that this happens when
mod_expires placed before mod_php5 in apache config (in particular in Debian Etch)

in this case mod_expires can`t discover MIME type of page, and this ExpiresByType text/html A1 don`t work for dynamically generated pages

this

<FilesMatch "\.(php)$">
ExpiresActive Off
</FilesMatch>

is interesting solution (I dont hip upon this idea, I just set off mod_expires in my case)

Update: Thax Davy Van Den Bremt! It works!

davyvdb’s picture

Status: Active » Needs review

Thanks a lot. I've sent this issue to my hosting provider. Let's see if this is the right solution.

davyvdb’s picture

I am getting 2 Expires values now

Expires: Sun, 19 Nov 1978 05:00:00 GMT, Thu, 14 May 2009 08:06:37 GMT

Server is running mod_suphp

I'll check with my client if he experiences issues in this setup.

catch’s picture

Priority: Critical » Normal
Status: Needs review » Active

No patch here, looks like a server config issue.

c960657’s picture

Is this still an issue after #147310: Implement better cache headers for reverse proxies has landed in HEAD?

c960657’s picture

Status: Active » Fixed

With the patch for #147310: Implement better cache headers for reverse proxies, .htaccess turns off ExpiresActive for index.php as suggested. Marking this issue fixed.

Damien Tournoud’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.