summaryrefslogtreecommitdiff
path: root/docs/manual/mod/mod_expires.html
blob: 141a96959839998fbd6955564ee01696e8b01762 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
 <HEAD>
  <TITLE>Apache module mod_expires</TITLE>
 </HEAD>
<!-- Background white, links blue (unvisited), navy (visited), red (active) -->
 <BODY
  BGCOLOR="#FFFFFF"
  TEXT="#000000"
  LINK="#0000FF"
  VLINK="#000080"
  ALINK="#FF0000"
 >
  <!--#include virtual="header.html" -->
  <H1 ALIGN="CENTER">Module mod_expires</H1>
  <P>
  This module is contained in the <CODE>mod_expires.c</CODE> file, and
  is <STRONG>not</STRONG> compiled in by default.  It provides for the
  generation of <CODE>Expires</CODE> headers according to user-specified
  criteria.
  </P>
  <H2>Summary</H2>
  <P>
  This module controls the setting of the <CODE>Expires</CODE> HTTP
  header in server responses.  The expiration date can set to be
  relative to either the time the source file was last modified, or to
  the time of the client access.
  </P>
  <P>
  The <CODE>Expires</CODE> HTTP header is an instruction to the client
  about the document's validity and persistence.  If cached, the document
  may be fetched from the cache rather than from the source until this
  time has passed.  After that, the cache copy is considered
  &quot;expired&quot; and invalid, and a new copy must be obtained from
  the source.
  </P>
  <H2>Directives</H2>
  <P>
  <MENU>
   <LI><A
        HREF="#expiresactive"
       >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>