2 <!DOCTYPE modulesynopsis SYSTEM "../style/modulesynopsis.dtd">
3 <?xml-stylesheet type="text/xsl" href="../style/manual.xsl"?>
6 <name>mod_expires</name>
7 <description>Generation of
8 <code>Expires</code> HTTP headers according to user-specified
10 <status>Extension</status>
11 <sourcefile>mod_expires.c</sourcefile>
12 <identifier>expires_module</identifier>
15 <p>This module controls the setting of the <code>Expires</code>
16 HTTP header in server responses. The expiration date can set to
17 be relative to either the time the source file was last
18 modified, or to the time of the client access.</p>
20 <p>The <code>Expires</code> HTTP header is an instruction to
21 the client about the document's validity and persistence. If
22 cached, the document may be fetched from the cache rather than
23 from the source until this time has passed. After that, the
24 cache copy is considered "expired" and invalid, and a new copy
25 must be obtained from the source.</p>
28 <section id="AltSyn"><title>Alternate Interval
31 <p>The <directive module="mod_expires">ExpiresDefault</directive> and
32 <directive module="mod_expires">ExpiresByType</directive> directives
33 can also be defined in a more readable syntax of the form:</p>
36 ExpiresDefault "<base> [plus] {<num>
38 ExpiresByType type/encoding "<base> [plus]
39 {<num> <type>}*"
42 <p>where <base> is one of:</p>
45 <li><code>access</code></li>
47 <li><code>now</code> (equivalent to
48 '<code>access</code>')</li>
50 <li><code>modification</code></li>
53 <p>The '<code>plus</code>' keyword is optional. <num>
54 should be an integer value [acceptable to <code>atoi()</code>],
55 and <type> is one of:</p>
58 <li><code>years</code></li>
60 <li><code>months</code></li>
62 <li><code>weeks</code></li>
64 <li><code>days</code></li>
66 <li><code>hours</code></li>
68 <li><code>minutes</code></li>
70 <li><code>seconds</code></li>
73 <p>For example, any of the following directives can be used to
74 make documents expire 1 month after being accessed, by
78 ExpiresDefault "access plus 1 month"<br />
79 ExpiresDefault "access plus 4 weeks"<br />
80 ExpiresDefault "access plus 30 days"
83 <p>The expiry time can be fine-tuned by adding several
84 '<num> <type>' clauses:</p>
87 ExpiresByType text/html "access plus 1 month 15
89 ExpiresByType image/gif "modification plus 5 hours 3
93 <p>Note that if you use a modification date based setting, the
94 Expires header will <strong>not</strong> be added to content
95 that does not come from a file on disk. This is due to the fact
96 that there is no modification time for such content.</p>
100 <name>ExpiresActive</name>
101 <description>Enables generation of <code>Expires</code> headers</description>
102 <syntax>ExpiresActive On|Off</syntax>
103 <contextlist><context>server config</context>
104 <context>virtual host</context><context>directory</context>
105 <context>.htaccess</context></contextlist>
106 <override>Indexes</override>
109 <p>This directive enables or disables the generation of the
110 <code>Expires</code> header for the document realm in question.
111 (That is, if found in an <code>.htaccess</code> file, for
112 instance, it applies only to documents generated from that
113 directory.) If set to <em><code>Off</code></em>, no
114 <code>Expires</code> header will be generated for any document
115 in the realm (unless overridden at a lower level, such as an
116 <code>.htaccess</code> file overriding a server config file).
117 If set to <em><code>On</code></em>, the header will be added to
118 served documents according to the criteria defined by the
119 <directive module="mod_expires">ExpiresByType</directive> and
120 <directive module="mod_expires">ExpiresDefault</directive> directives
123 <p>Note that this directive does not guarantee that an
124 <code>Expires</code> header will be generated. If the criteria
125 aren't met, no header will be sent, and the effect will be as
126 though this directive wasn't even specified.</p>
131 <name>ExpiresByType</name>
132 <description>Value of the <code>Expires</code> header configured
133 by MIME type</description>
134 <syntax>ExpiresByType
135 <em>MIME-type <code>seconds</em></syntax>
136 <contextlist><context>server config</context>
137 <context>virtual host</context><context>directory</context>
138 <context>.htaccess</context></contextlist>
139 <override>Indexes</override>
142 <p>This directive defines the value of the <code>Expires</code>
143 header generated for documents of the specified type
144 (<em>e.g.</em>, <code>text/html</code>). The second argument
145 sets the number of seconds that will be added to a base time to
146 construct the expiration date.</p>
148 <p>The base time is either the last modification time of the
149 file, or the time of the client's access to the document. Which
150 should be used is specified by the
151 <code><em><code></em></code> field; <strong>M</strong>
152 means that the file's last modification time should be used as
153 the base time, and <strong>A</strong> means the client's access
154 time should be used.</p>
156 <p>The difference in effect is subtle. If <em>M</em> is used,
157 all current copies of the document in all caches will expire at
158 the same time, which can be good for something like a weekly
159 notice that's always found at the same URL. If <em>A</em> is
160 used, the date of expiration is different for each client; this
161 can be good for image files that don't change very often,
162 particularly for a set of related documents that all refer to
163 the same images (<em>i.e.</em>, the images will be accessed
164 repeatedly within a relatively short timespan).</p>
166 <p><strong>Example:</strong></p>
168 # enable expirations<br />
169 ExpiresActive On<br />
170 # expire GIF images after a month in the client's cache<br />
171 ExpiresByType image/gif A2592000<br />
172 # HTML documents are good for a week from the time they were changed<br />
173 ExpiresByType text/html M604800
176 <p>Note that this directive only has effect if
177 <code>ExpiresActive On</code> has been specified. It overrides,
178 for the specified MIME type <em>only</em>, any expiration date
179 set by the <directive module="mod_expires">ExpiresDefault</directive>
182 <p>You can also specify the expiration time calculation using
183 an <a href="#AltSyn">alternate syntax</a>, described earlier in
189 <name>ExpiresDefault</name>
190 <description>Default algorithm for calculating expiration time</description>
191 <syntax>ExpiresDefault <em><code>seconds</em></syntax>
192 <contextlist><context>server config</context>
193 <context>virtual host</context><context>directory</context>
194 <context>.htaccess</context></contextlist>
195 <override>Indexes</override>
198 <p>This directive sets the default algorithm for calculating the
199 expiration time for all documents in the affected realm. It can be
200 overridden on a type-by-type basis by the <directive
201 module="mod_expires">ExpiresByType</directive> directive. See the
202 description of that directive for details about the syntax of the
203 argument, and the <a href="#AltSyn">alternate syntax</a>
204 description as well.</p>