Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment #1
drummThis code in .htaccess is the same in the development version.
Comment #2
davyvdb CreditAttribution: davyvdb commentedI 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');
Comment #3
Anonymous (not verified) CreditAttribution: Anonymous commentedI 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
Comment #4
bismigalis CreditAttribution: bismigalis commentedI 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 pagesthis
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!
Comment #5
davyvdb CreditAttribution: davyvdb commentedThanks a lot. I've sent this issue to my hosting provider. Let's see if this is the right solution.
Comment #6
davyvdb CreditAttribution: davyvdb commentedI 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.
Comment #7
catchNo patch here, looks like a server config issue.
Comment #8
c960657 CreditAttribution: c960657 commentedIs this still an issue after #147310: Implement better cache headers for reverse proxies has landed in HEAD?
Comment #9
c960657 CreditAttribution: c960657 commentedWith the patch for #147310: Implement better cache headers for reverse proxies, .htaccess turns off ExpiresActive for index.php as suggested. Marking this issue fixed.
Comment #10
Damien Tournoud CreditAttribution: Damien Tournoud commentedFor Drupal 6, please see #550488: Turn off mod_expires for all .php files.