Forcing caching with Apache2 – mod_expires and mod_headers

Problem: Even when you use mod_expires to cache content on your server, some redirects may break the cache headers so the mod_expires will not output the right headers. This especially seems to happen when you have CMSs like Joomla/Drupal with SEO features and are trying to cache them.

This is how the mod_expires was set up before

<IfModule mod_expires.c>
ExpiresDefault "access plus 20 minutes"
ExpiresActive On
</IfModule>

But these lines using mod_headers need to be added to remove the no-cache directives being output by the CMS:

Header unset Cache-Control:
Header unset Expires:
Header unset Pragma:
Header unset Keep-Alive:
Header unset Connection:

That removed the HTTP cache headers output by the CMS that seemed to be caused by the redirects (and which mod_expires was not replacing.)

You may need to enable mod_headers; it wasn’t enabled on my installation of Apache 2.2. The command to do that is:

a2enmod headers
About these ads

1 comment so far

  1. name on

    Thanks a lot!
    Solved my problem.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: