mod_expires.html revision f9b3be308809978f797e0c57b296147532a4313c
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin <!-- Background white, links blue (unvisited), navy (visited), red (active) -->
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin BGCOLOR="#FFFFFF"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin TEXT="#000000"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin LINK="#0000FF"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin VLINK="#000080"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin ALINK="#FF0000"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin <!--#include virtual="header.html" -->
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin This module is contained in the <CODE>mod_expires.c</CODE> file, and
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin is <STRONG>not</STRONG> compiled in by default. It provides for the
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin generation of <CODE>Expires</CODE> headers according to user-specified
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin This module controls the setting of the <CODE>Expires</CODE> HTTP
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin header in server responses. The expiration date can set to be
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin relative to either the time the source file was last modified, or to
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin the time of the client access.
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin The <CODE>Expires</CODE> HTTP header is an instruction to the client
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin about the document's validity and persistence. If cached, the document
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin may be fetched from the cache rather than from the source until this
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin time has passed. After that, the cache copy is considered
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin "expired" and invalid, and a new copy must be obtained from
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin HREF="#expiresactive"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin >ExpiresActive</A>
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin HREF="#expiresbytype"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin >ExpiresByType</A>
ce67301fa82625f5594913e8ab6abf9e0aa461d0Roland Mainz HREF="#expiresdefault"
ce67301fa82625f5594913e8ab6abf9e0aa461d0Roland Mainz >ExpiresDefault</A>
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin ExpiresActive directive
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin <!--%plaintext <?INDEX {\tt ExpiresActive} directive> -->
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin <STRONG>Syntax:</STRONG> ExpiresActive <EM>boolean</EM>
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin <STRONG>Context:</STRONG> server config, virtual host, directory, .htaccess
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin This directive enables or disables the generation of the
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin <CODE>Expires</CODE> header for the document realm in question. (That
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin is, if found in an <CODE>.htaccess</CODE> file, for instance, it
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin applies only to documents generated from that directory.) If set to
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin <EM><CODE>Off</CODE></EM>, no <CODE>Expires</CODE> header will be
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin generated for any document in the realm (unless overridden at a lower
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin level, such as an <CODE>.htaccess</CODE> file overriding a server
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin config file). If set to <EM><CODE>On</CODE></EM>, the header will be
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin added to served documents according to the criteria defined by the
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin HREF="#expiresbytype"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin >ExpiresByType</A>
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin HREF="#expiresdefault"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin >ExpiresDefault</A>
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin Note that this directive does not guarantee that an
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin <CODE>Expires</CODE> header will be generated. If the criteria aren't
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin met, no header will be sent, and the effect will be as though this
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin directive wasn't even specified.
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin ExpiresByType directive
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin <!--%plaintext <?INDEX {\tt ExpiresByType} directive> -->
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin <STRONG>Syntax:</STRONG> ExpiresByType <EM>mime-type <code>seconds</EM>
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin <STRONG>Context:</STRONG> server config, virtual host, directory, .htaccess
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin This directive defines the value of the <CODE>Expires</CODE> header
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin generated for documents of the specified type (<EM>e.g.</EM>,
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin <CODE>text/html</CODE>). The second argument sets the number of
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin seconds that will be added to a base time to construct the expiration
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin The base time is either the last modification time of the file, or the
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin time of the client's access to the document. Which should be used is
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin specified by the <CODE><EM><code></EM></CODE> field;
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin <STRONG>M</STRONG> means that the file's last modification time should
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin be used as the base time, and <STRONG>A</STRONG> means the client's
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin access time should be used.
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin The difference in effect is subtle. If <EM>M</EM> is used, all current
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin copies of the document in all caches will expire at the same time,
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin which can be good for something like a weekly notice that's always
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin found at the same URL. If <EM>A</EM> is used, the date of expiration
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin is different for each client; this can be good for image files that
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin don't change very often, particularly for a set of related documents
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin that all refer to the same images (<EM>i.e.</EM>, the images will be
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin accessed repeatedly within a relatively short timespan).
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin ExpiresActive On # enable expirations
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin ExpiresByType image/gif A2592000 # expire GIF images after a month
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin # in the client's cache
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin ExpiresByType text/html M604800 # HTML documents are good for a
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin # week from the time they were
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin # changed, period
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin Note that this directive only has effect if <CODE>ExpiresActive
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin On</CODE> has been specified. It overrides, for the specified MIME
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin type <EM>only</EM>, any expiration date set by the
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin HREF="#expiresdefault"
ce67301fa82625f5594913e8ab6abf9e0aa461d0Roland Mainz >ExpiresDefault</A>
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin You can also specify the expiration time calculation using an
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin HREF="#AltSyn"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin >alternate syntax</A>,
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin described later in this document.
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin ExpiresDefault directive
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin <!--%plaintext <?INDEX {\tt ExpiresDefault} directive> -->
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin <STRONG>Syntax:</STRONG> ExpiresDefault <EM><code>seconds</EM>
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin <STRONG>Context:</STRONG> server config, virtual host, directory, .htaccess
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin This directive sets the default algorithm for calculating the
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin expiration time for all documents in the affected realm. It can be
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin overridden on a type-by-type basis by the
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin HREF="#expiresbytype"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin >ExpiresByType</A>
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin directive. See the description of that directive for details about
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin the syntax of the argument, and the
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin HREF="#AltSyn"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin >alternate syntax</A>
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin description as well.
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin HREF="#expiresdefault"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin HREF="#expiresbytype"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin directives can also be defined in a more readable syntax of the form:
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin <DD><CODE>ExpiresDefault "<base> [plus] {<num> <type>}*"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin ExpiresByType type/encoding "<base> [plus] {<num> <type>}*"</CODE>
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin where <base> is one of:
ce67301fa82625f5594913e8ab6abf9e0aa461d0Roland Mainz <LI><SAMP>now</SAMP> (equivalent to '<SAMP>access</SAMP>')
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin The '<SAMP>plus</SAMP>' keyword is optional. <num> should be an
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin integer value [acceptable to <SAMP>atoi()</SAMP>], and <type>
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin For example, any of the following directives can be used to make
a4aeef46cda1835da2b19f8f62b4526de6521e6cDonghai Qiao documents expire 1 month after being accessed, by default:
a4aeef46cda1835da2b19f8f62b4526de6521e6cDonghai Qiao ExpiresDefault "access plus 4 weeks"
a4aeef46cda1835da2b19f8f62b4526de6521e6cDonghai Qiao ExpiresDefault "access plus 30 days"</CODE>
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin The expiry time can be fine-tuned by adding several '<num> <type>'
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin <DD><CODE>ExpiresByType text/html "access plus 1 month 15 days 2 hours"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin ExpiresByType image/gif "modification plus 5 hours 3 minutes"</CODE>
<!--#include virtual="footer.html" -->