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