3.15. Expirations

Apache Version 1.2 brought the expires module, mod_expires, into the main distribution. The point of this module is to allow the webmaster to set the returned headers to pass information to clients' browsers about documents that will need to be reloaded because they are apt to change, or alternatively, that are not going to change for a long time and can therefore be cached. There are three directives.

3.15.1. ExpiresActive

ExpiresActive [on|off]
Anywhere, .htaccess when AllowOverride Indexes

ExpiresActive simply switches the expiration mechanism on and off.

3.15.2. ExpiresByType

ExpiresByType mime-type time
Anywhere, .htaccess when AllowOverride Indexes

ExpiresByType takes two arguments. mime-type specifies a MIME type of file; time specifies how long these files are to remain active. There are two versions of the syntax. The first is:

               code 
               seconds
            

There is no space between code and seconds. code is one of the following:

A

Access time (or now, in other words)

M

Last modification time of the file

seconds is simply a number. For example:

A565656

specifies 565656 seconds after the access time.

The more readable second format is:

               base [plus] number 
               type [number 
               type ...]

where base is one of the following:

access

Access time

now

Synonym for access

modification

Last modification time of the file

The plus keyword is optional, and type is one of the following:

  • years

  • months

  • weeks

  • days

  • hours

  • minutes

  • seconds

For example: ...

Get Apache: The Definitive Guide, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.