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