mod_expires.html revision 933b5881f4e2437c0119cc8d41fe63e37f7d30ac
89a126810703c666309310d0f3189e9834d70b5bTimo Sirainen<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
25fdbae285d682b7e54ac103ccfb95e032b6ff1fTimo Sirainen<HTML>
25fdbae285d682b7e54ac103ccfb95e032b6ff1fTimo Sirainen <HEAD>
25fdbae285d682b7e54ac103ccfb95e032b6ff1fTimo Sirainen <TITLE>Apache module mod_expires</TITLE>
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen </HEAD>
25fdbae285d682b7e54ac103ccfb95e032b6ff1fTimo Sirainen<!-- Background white, links blue (unvisited), navy (visited), red (active) -->
25fdbae285d682b7e54ac103ccfb95e032b6ff1fTimo Sirainen <BODY
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainen BGCOLOR="#FFFFFF"
25fdbae285d682b7e54ac103ccfb95e032b6ff1fTimo Sirainen TEXT="#000000"
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen LINK="#0000FF"
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen VLINK="#000080"
25fdbae285d682b7e54ac103ccfb95e032b6ff1fTimo Sirainen ALINK="#FF0000"
e5ee67f18b03015c88b579c8c1f17ebe6ce19b76Timo Sirainen >
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainen <!--#include virtual="header.html" -->
25fdbae285d682b7e54ac103ccfb95e032b6ff1fTimo Sirainen <H1 ALIGN="CENTER">Module mod_expires</H1>
06b3ce71a592e5575b5e1d4f412bd364dc6da69dTimo Sirainen <P>
06b3ce71a592e5575b5e1d4f412bd364dc6da69dTimo Sirainen This module is contained in the <CODE>mod_expires.c</CODE> file, and
06b3ce71a592e5575b5e1d4f412bd364dc6da69dTimo Sirainen is <STRONG>not</STRONG> compiled in by default. It provides for the
06b3ce71a592e5575b5e1d4f412bd364dc6da69dTimo Sirainen generation of <CODE>Expires</CODE> headers according to user-specified
06b3ce71a592e5575b5e1d4f412bd364dc6da69dTimo Sirainen criteria.
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen </P>
41da195263f4c7f0eaf58f3ecee4d9ceb92ae8c1Timo Sirainen <H2>Summary</H2>
41da195263f4c7f0eaf58f3ecee4d9ceb92ae8c1Timo Sirainen <P>
345212e8f61ebf14ff4f80df26df9e655eb5121eTimo Sirainen This module controls the setting of the <CODE>Expires</CODE> HTTP
25fdbae285d682b7e54ac103ccfb95e032b6ff1fTimo Sirainen header in server responses. The expiration date can set to be
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen relative to either the time the source file was last modified, or to
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen the time of the client access.
abd162fee549940f212f20fc1d7442d386cf8c3aTimo Sirainen </P>
abd162fee549940f212f20fc1d7442d386cf8c3aTimo Sirainen <P>
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainen The <CODE>Expires</CODE> HTTP header is an instruction to the client
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainen about the document's validity and persistence. If cached, the document
abd162fee549940f212f20fc1d7442d386cf8c3aTimo Sirainen may be fetched from the cache rather than from the source until this
25fdbae285d682b7e54ac103ccfb95e032b6ff1fTimo Sirainen time has passed. After that, the cache copy is considered
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainen &quot;expired&quot; and invalid, and a new copy must be obtained from
7774ddcab3661f24c473bd74ad35f717f8bd7110Timo Sirainen the source.
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainen </P>
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainen <H2>Directives</H2>
63f36c2b47217fc2dc4ed49cfc1907311d5ed366Timo Sirainen <P>
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen <MENU>
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen <LI><A
25fdbae285d682b7e54ac103ccfb95e032b6ff1fTimo Sirainen HREF="#expiresactive"
25fdbae285d682b7e54ac103ccfb95e032b6ff1fTimo Sirainen >ExpiresActive</A>
</LI>
<LI><A
HREF="#expiresbytype"
>ExpiresByType</A>
</LI>
<LI><A
HREF="#expiresdefault"
>ExpiresDefault</A>
</LI>
</MENU>
<HR>
<H2><A NAME="expiresactive">
ExpiresActive directive
</A></H2>
<!--%plaintext &lt;?INDEX {\tt ExpiresActive} directive&gt; -->
<P>
<A
HREF="directive-dict.html#Syntax"
REL="Help"
><STRONG>Syntax:</STRONG></A> ExpiresActive <EM>boolean</EM>
<BR>
<A
HREF="directive-dict.html#Context"
REL="Help"
><STRONG>Context:</STRONG></A> server config, virtual host, directory,
.htaccess
<BR>
<A
HREF="directive-dict.html#Override"
REL="Help"
><STRONG>Override:</STRONG></A> Indexes
<BR>
<A
HREF="directive-dict.html#Status"
REL="Help"
><STRONG>Status:</STRONG></A> Extension
<BR>
<A
HREF="directive-dict.html#Module"
REL="Help"
><STRONG>Module:</STRONG></A> mod_expires
</P>
<P>
This directive enables or disables the generation of the
<CODE>Expires</CODE> header for the document realm in question. (That
is, if found in an <CODE>.htaccess</CODE> file, for instance, it
applies only to documents generated from that directory.) If set to
<EM><CODE>Off</CODE></EM>, no <CODE>Expires</CODE> header will be
generated for any document in the realm (unless overridden at a lower
level, such as an <CODE>.htaccess</CODE> file overriding a server
config file). If set to <EM><CODE>On</CODE></EM>, the header will be
added to served documents according to the criteria defined by the
<A
HREF="#expiresbytype"
>ExpiresByType</A>
and
<A
HREF="#expiresdefault"
>ExpiresDefault</A>
directives (<EM>q.v.</EM>).
</P>
<P>
Note that this directive does not guarantee that an
<CODE>Expires</CODE> header will be generated. If the criteria aren't
met, no header will be sent, and the effect will be as though this
directive wasn't even specified.
</P>
<HR>
<H2><A NAME="expiresbytype">
ExpiresByType directive
</A></H2>
<!--%plaintext &lt;?INDEX {\tt ExpiresByType} directive&gt; -->
<P>
<A
HREF="directive-dict.html#Syntax"
REL="Help"
><STRONG>Syntax:</STRONG></A> ExpiresByType <EM>mime-type
&lt;code&gt;seconds</EM>
<BR>
<A
HREF="directive-dict.html#Context"
REL="Help"
><STRONG>Context:</STRONG></A> server config, virtual host, directory,
.htaccess
<BR>
<A
HREF="directive-dict.html#Override"
REL="Help"
><STRONG>Override:</STRONG></A> Indexes
<BR>
<A
HREF="directive-dict.html#Status"
REL="Help"
><STRONG>Status:</STRONG></A> Extension
<BR>
<A
HREF="directive-dict.html#Module"
REL="Help"
><STRONG>Module:</STRONG></A> mod_expires
</P>
<P>
This directive defines the value of the <CODE>Expires</CODE> header
generated for documents of the specified type (<EM>e.g.</EM>,
<CODE>text/html</CODE>). The second argument sets the number of
seconds that will be added to a base time to construct the expiration
date.
</P>
<P>
The base time is either the last modification time of the file, or the
time of the client's access to the document. Which should be used is
specified by the <CODE><EM>&lt;code&gt;</EM></CODE> field;
<STRONG>M</STRONG> means that the file's last modification time should
be used as the base time, and <STRONG>A</STRONG> means the client's
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>
<A
HREF="directive-dict.html#Syntax"
REL="Help"
><STRONG>Syntax:</STRONG></A> ExpiresDefault <EM>&lt;code&gt;seconds</EM>
<BR>
<A
HREF="directive-dict.html#Context"
REL="Help"
><STRONG>Context:</STRONG></A> server config, virtual host, directory,
.htaccess
<BR>
<A
HREF="directive-dict.html#Override"
REL="Help"
><STRONG>Override:</STRONG></A> Indexes
<BR>
<A
HREF="directive-dict.html#Status"
REL="Help"
><STRONG>Status:</STRONG></A> Extension
<BR>
<A
HREF="directive-dict.html#Module"
REL="Help"
><STRONG>Module:</STRONG></A> 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>
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>
<P>
Note that if you use a modification date based setting, the Expires
header will <STRONG>not</STRONG> 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.
<!--#include virtual="footer.html" -->
</BODY>
</HTML>