Module mod_expires

Important: Information for this topic supports the latest PTF levels for HTTP Server for i5/OS . It is recommended that you install the latest PTFs to upgrade to the latest level of the HTTP Server for i5/OS. Some of the topics documented here are not available prior to this update. See http://www.ibm.com/servers/eserver/iseries/software/http/services/service.htm Link outside Information Center for more information.

Summary

This module controls the setting of the Expires HTTP header in server responses. The expiration date can be set relative to either the time that the source file was last modified, or relative to the time that the client accessed the server.

The Expires HTTP header is an instruction to the client regarding the document's validity and persistence. If cached, the document may be retrieved from the cache rather than from the source until the allocated time has passed. After this occurs, the cache copy is considered "expired" and a new copy must be obtained from the source.

Alternate Interval Syntax

The ExpiresDefault and ExpiresByType directives can also be defined in a more readable syntax of the form:

ExpiresDefault "<base> [plus] {<num> <type>}*"
ExpiresByType type|encoding "<base> [plus] {<num> <type>}*"

The <base> argument is one of the following:

The [plus] keyword is optional. The <num> argument should be an integer value [acceptable to atoi()], and <type> is one of the following:

For example, any of the following directives can be used to make documents expire 1 month after being accessed, by default:

ExpiresDefault "access plus 1 month" 
ExpiresDefault "access plus 4 weeks" 
ExpiresDefault "access plus 30 days"
Note: Time is stored in seconds. The value month is actually calculated as 60*60*24*30 seconds. Keep in mind that one month is equal 30 days, and 4 weeks is only equal to 28 days. If you specify 52 weeks, it is calculated as 362 days instead of 365 days.

The expiry time can be fine-tuned by adding several <num> and <type> arguments. For example:

ExpiresByType text/html"access plus 1 month 15 days 2 hours" 
ExpiresByType image/gif "modification plus 5 hours 3 minutes"
Note: If you use a modification date based setting, the Expires header is added only to content that comes from a file on a disk, because there is no modification time for content that does not come from a file on a disk.

Directives

ExpiresActive

Module: mod_expires
Syntax: ExpiresActive on | off
Default: ExpiresActive off
Context: server config, virtual host, directory, .htaccess
Override: Indexes
Origin: Apache
Example: ExpiresActive on

The ExpiresActive directive enables or disables the generation of the Expires header for the document realm in question. If this directive is found in an .htaccess file it only applies to documents generated from that directory.

Parameter: on | off
  • If set to on, an Expires header will be added to served documents according to criteria set by the ExpiresByType and ExpiresDefault directives.
  • If set to off, an Expires header will not be generated for any document in the realm (unless overridden at a lower level, such as an .htaccess file overriding a server config file).
Note: This directive does not guarantee that an Expires header will be generated. If the criteria is not met, no header will be sent, and the effect will be as though this directive was never specified.

ExpiresByType

Module: mod_expires
Syntax: ExpiresByType MIME-type code seconds | "<base> [plus] <num> <type>"
Default: none
Context: server config, virtual host, directory, .htaccess
Override: Indexes
Origin: Apache
Example: ExpiresByType image/gif A2592000
Example: ExpiresByType text/html "access plus 30 days"

The ExpiresByType directive defines the value of the Expires header generated for documents of the specified type ( for example, text/html). The second argument sets the number of seconds that will be added to a base time to construct the expiration date.

The base time is either the last modification time of the file, or the time of the client's access to the document. Whether access time or modification time should be used is specified by the code field. M means that the file's last modification time should be used as the base time, and A means the client's access time should be used.

The difference in effect between the A and the M is minimal. If M is used, all current copies of the document in all caches will expire at the same time. This could be useful for something like a weekly notice that is always found at the same URL. If A is used, the date of expiration is different for each client. This could be useful for image files that do not change very often, particularly for a set of related documents that all refer to the same images ( for example, the images will be accessed repeatedly within a relatively short time span).

Parameter One: MIME-type
  • The document type for which an Expires header should be generated.
Parameter Two: code
  • The code parameter specifies one of two possible choices. Specify A if the expiration time should be calculated from the time the resource was accessed. Specify M if the expiration time should be calculated from the last modified date of the resource.
Parameter Three: seconds
  • The seconds parameter is a number of seconds until the resource expires.

Here is an example to specify the expiration time calculation. For examples using alternate syntax, see the beginning of this article.

#enable expirations 
ExpiresActive on 
#expire GIF images after a month in the clients cache
ExpiresByType image/fig A2592000 
#HTML documents are good for a week from the time they were changed 
ExpiresByType text/html M604800
Note: This directive only has effect if ExpiresActive On has been specified. It overrides, for the specified MIME type only, any expiration date set by the ExpiresDefault directive. If you use a modification date based setting, the Expires header will not be added to content that does not come from a file on disk. This is due to the fact that there is no modification time for such content.

ExpiresDefault

Module: mod_expires
Syntax: ExpiresDefault code seconds| "<base> [plus] <num> <type>"
Default: none
Context: server config, virtual host, directory, .htaccess
Override: Indexes
Origin: Apache
Example: ExpiresDefault A2592000
Example: ExpiresDefault "access plus 1 month"

The ExpiresDefault directive sets the default algorithm for calculating the expiration time for all documents in the affected realm. It can be overridden on a type-by-type basis by the ExpiresByType directive. See the description of the ExpiresByType directive for details about the syntax of the argument, and the alternate syntax description as well.

Parameter One: code
  • The code parameter specifies has two arguments. Specify A if the expiration time should be calculated from the time the resource was accessed. Specify M if the expiration time should be calculated from the last modified date of the resource.
Parameter Two: seconds
  • The seconds parameter is a number of seconds until the resource expires.
Note:
  • If you use a modification date based setting, the Expires header will not be added to content that does not come from a file on disk. This is due to the fact that there is no modification time for such content.
  • You can also specify the expiration time calculation using the alternate interval syntax. For examples using alternate syntax, see the beginning of this article.