Using Apache Expires Headers to Save Bandwidth

Apache HTTP Server is by far the most widely-used web server on the Internet.  Chances are, your Linux or Unix-like dedicated server runs it to serve up websites to the public.  Doing this uses bandwidth, and there is no way to get around it in principle, but you can take some steps to minimize the amount of bandwidth Apache uses.

The Expire Headers setting interfaces directly with the user agent (also called a client or web browser) and tells it when it is necessary to refresh its cache on a particular page.  The benefit of caching is that a web browser does not have to reload the site every time it visits, which is especially useful for sites with many graphics.  Therefore, even dynamic websites can benefit from caching.

By using expiry tags, you can make your website seem faster and more responsive.  For static images, for example, you can set long expiry tags because there is little chance of them changing.  You can also use them for infrequently-updated pages, like rss feeds.  For example, if you wanted your RSS feed to be updated every four hours, you can set the expiry tags as follows:

ExpiresActive On
ExpiresDefault “access plus 4 hours”

You can use the mod_expires directive in your Apache configuration, virtual host configuration, and .htaccess files.  For more information about mod_expires, see the Apache online documentation.