1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 3 4<html xmlns="http://www.w3.org/1999/xhtml"> 5 <head> 6 <meta name="generator" content="HTML Tidy, see www.w3.org" /> 7 8 <title>Apache module mod_expires</title> 9 </head> 10 <!-- Background white, links blue (unvisited), navy (visited), red (active) --> 11 12 <body bgcolor="#FFFFFF" text="#000000" link="#0000FF" 13 vlink="#000080" alink="#FF0000"> 14 <div align="CENTER"> 15 <img src="../images/sub.gif" alt="[APACHE DOCUMENTATION]" /> 16 17 <h3>Apache HTTP Server Version 1.3</h3> 18 </div> 19 20 21 <h1 align="CENTER">Module mod_expires</h1> 22 23 <p>This module provides for the generation of 24 <code>Expires</code> HTTP headers according to user-specified 25 criteria.</p> 26 27 <p><a href="module-dict.html#Status" 28 rel="Help"><strong>Status:</strong></a> Extension<br /> 29 <a href="module-dict.html#SourceFile" 30 rel="Help"><strong>Source File:</strong></a> 31 mod_expires.c<br /> 32 <a href="module-dict.html#ModuleIdentifier" 33 rel="Help"><strong>Module Identifier:</strong></a> 34 expires_module<br /> 35 <a href="module-dict.html#Compatibility" 36 rel="Help"><strong>Compatibility:</strong></a> Available in 37 Apache 1.2 and later.</p> 38 39 <h2>Summary</h2> 40 41 <p>This module controls the setting of the <code>Expires</code> 42 HTTP header in server responses. The expiration date can set to 43 be relative to either the time the source file was last 44 modified, or to the time of the client access.</p> 45 46 <p>The <code>Expires</code> HTTP header is an instruction to 47 the client about the document's validity and persistence. If 48 cached, the document may be fetched from the cache rather than 49 from the source until this time has passed. After that, the 50 cache copy is considered "expired" and invalid, and a new copy 51 must be obtained from the source.</p> 52 53 <h2>Directives</h2> 54 55 <ul> 56 <li><a href="#expiresactive">ExpiresActive</a></li> 57 58 <li><a href="#expiresbytype">ExpiresByType</a></li> 59 60 <li><a href="#expiresdefault">ExpiresDefault</a></li> 61 </ul> 62 63 <h2><a id="AltSyn" name="AltSyn">Alternate Interval 64 Syntax</a></h2> 65 66 <p>The <a 67 href="#expiresdefault"><samp>ExpiresDefault</samp></a> and <a 68 href="#expiresbytype"><samp>ExpiresByType</samp></a> directives 69 can also be defined in a more readable syntax of the form:</p> 70 71 <dl> 72 <dd><code>ExpiresDefault "<base> [plus] {<num> 73 <type>}*"<br /> 74 ExpiresByType type/encoding "<base> [plus] 75 {<num> <type>}*"</code></dd> 76 </dl> 77 78 <p>where <base> is one of:</p> 79 80 <ul> 81 <li><samp>access</samp></li> 82 83 <li><samp>now</samp> (equivalent to 84 '<samp>access</samp>')</li> 85 86 <li><samp>modification</samp></li> 87 </ul> 88 89 <p>The '<samp>plus</samp>' keyword is optional. <num> 90 should be an integer value [acceptable to <samp>atoi()</samp>], 91 and <type> is one of:</p> 92 93 <ul> 94 <li><samp>years</samp></li> 95 96 <li><samp>months</samp></li> 97 98 <li><samp>weeks</samp></li> 99 100 <li><samp>days</samp></li> 101 102 <li><samp>hours</samp></li> 103 104 <li><samp>minutes</samp></li> 105 106 <li><samp>seconds</samp></li> 107 </ul> 108 109 <p>For example, any of the following directives can be used to 110 make documents expire 1 month after being accessed, by 111 default:</p> 112 113 <dl> 114 <dd><code>ExpiresDefault "access plus 1 month"<br /> 115 ExpiresDefault "access plus 4 weeks"<br /> 116 ExpiresDefault "access plus 30 days"</code></dd> 117 </dl> 118 119 <p>The expiry time can be fine-tuned by adding several 120 '<num> <type>' clauses:</p> 121 122 <dl> 123 <dd><code>ExpiresByType text/html "access plus 1 month 15 124 days 2 hours"<br /> 125 ExpiresByType image/gif "modification plus 5 hours 3 126 minutes"</code></dd> 127 </dl> 128 129 <p>Note that if you use a modification date based setting, the 130 Expires header will <strong>not</strong> be added to content 131 that does not come from a file on disk. This is due to the fact 132 that there is no modification time for such content.</p> 133 <hr /> 134 135 <h2><a id="expiresactive" name="expiresactive">ExpiresActive 136 directive</a></h2> 137 138 <p><a href="directive-dict.html#Syntax" 139 rel="Help"><strong>Syntax:</strong></a> ExpiresActive 140 on|off<br /> 141 <a href="directive-dict.html#Context" 142 rel="Help"><strong>Context:</strong></a> server config, virtual 143 host, directory, .htaccess<br /> 144 <a href="directive-dict.html#Override" 145 rel="Help"><strong>Override:</strong></a> Indexes<br /> 146 <a href="directive-dict.html#Status" 147 rel="Help"><strong>Status:</strong></a> Extension<br /> 148 <a href="directive-dict.html#Module" 149 rel="Help"><strong>Module:</strong></a> mod_expires</p> 150 151 <p>This directive enables or disables the generation of the 152 <code>Expires</code> header for the document realm in question. 153 (That is, if found in an <code>.htaccess</code> file, for 154 instance, it applies only to documents generated from that 155 directory.) If set to <em><code>Off</code></em>, no 156 <code>Expires</code> header will be generated for any document 157 in the realm (unless overridden at a lower level, such as an 158 <code>.htaccess</code> file overriding a server config file). 159 If set to <em><code>On</code></em>, the header will be added to 160 served documents according to the criteria defined by the <a 161 href="#expiresbytype">ExpiresByType</a> and <a 162 href="#expiresdefault">ExpiresDefault</a> directives 163 (<em>q.v.</em>).</p> 164 165 <p>Note that this directive does not guarantee that an 166 <code>Expires</code> header will be generated. If the criteria 167 aren't met, no header will be sent, and the effect will be as 168 though this directive wasn't even specified.</p> 169 <hr /> 170 171 <h2><a id="expiresbytype" name="expiresbytype">ExpiresByType 172 directive</a></h2> 173 174 <p><a href="directive-dict.html#Syntax" 175 rel="Help"><strong>Syntax:</strong></a> ExpiresByType 176 <em>mime-type <code>seconds</em><br /> 177 <a href="directive-dict.html#Context" 178 rel="Help"><strong>Context:</strong></a> server config, virtual 179 host, directory, .htaccess<br /> 180 <a href="directive-dict.html#Override" 181 rel="Help"><strong>Override:</strong></a> Indexes<br /> 182 <a href="directive-dict.html#Status" 183 rel="Help"><strong>Status:</strong></a> Extension<br /> 184 <a href="directive-dict.html#Module" 185 rel="Help"><strong>Module:</strong></a> mod_expires</p> 186 187 <p>This directive defines the value of the <code>Expires</code> 188 header generated for documents of the specified type 189 (<em>e.g.</em>, <code>text/html</code>). The second argument 190 sets the number of seconds that will be added to a base time to 191 construct the expiration date.</p> 192 193 <p>The base time is either the last modification time of the 194 file, or the time of the client's access to the document. Which 195 should be used is specified by the 196 <code><em><code></em></code> field; <strong>M</strong> 197 means that the file's last modification time should be used as 198 the base time, and <strong>A</strong> means the client's access 199 time should be used.</p> 200 201 <p>The difference in effect is subtle. If <em>M</em> is used, 202 all current copies of the document in all caches will expire at 203 the same time, which can be good for something like a weekly 204 notice that's always found at the same URL. If <em>A</em> is 205 used, the date of expiration is different for each client; this 206 can be good for image files that don't change very often, 207 particularly for a set of related documents that all refer to 208 the same images (<em>i.e.</em>, the images will be accessed 209 repeatedly within a relatively short timespan).</p> 210 211 <p><strong>Example:</strong></p> 212<pre> 213 ExpiresActive On # enable expirations 214 ExpiresByType image/gif A2592000 # expire GIF images after a month 215 # in the client's cache 216 ExpiresByType text/html M604800 # HTML documents are good for a 217 # week from the time they were 218 # changed, period 219 220</pre> 221 222 <p>Note that this directive only has effect if 223 <code>ExpiresActive On</code> has been specified. It overrides, 224 for the specified MIME type <em>only</em>, any expiration date 225 set by the <a href="#expiresdefault">ExpiresDefault</a> 226 directive.</p> 227 228 <p>You can also specify the expiration time calculation using 229 an <a href="#AltSyn">alternate syntax</a>, described later in 230 this document.</p> 231 <hr /> 232 233 <h2><a id="expiresdefault" name="expiresdefault">ExpiresDefault 234 directive</a></h2> 235 236 <p><a href="directive-dict.html#Syntax" 237 rel="Help"><strong>Syntax:</strong></a> ExpiresDefault 238 <em><code>seconds</em><br /> 239 <a href="directive-dict.html#Context" 240 rel="Help"><strong>Context:</strong></a> server config, virtual 241 host, directory, .htaccess<br /> 242 <a href="directive-dict.html#Override" 243 rel="Help"><strong>Override:</strong></a> Indexes<br /> 244 <a href="directive-dict.html#Status" 245 rel="Help"><strong>Status:</strong></a> Extension<br /> 246 <a href="directive-dict.html#Module" 247 rel="Help"><strong>Module:</strong></a> mod_expires</p> 248 249 <p>This directive sets the default algorithm for calculating 250 the expiration time for all documents in the affected realm. It 251 can be overridden on a type-by-type basis by the <a 252 href="#expiresbytype">ExpiresByType</a> directive. See the 253 description of that directive for details about the syntax of 254 the argument, and the <a href="#AltSyn">alternate syntax</a> 255 description as well.</p> 256 <hr /> 257 258 <h3 align="CENTER">Apache HTTP Server Version 1.3</h3> 259 <a href="./"><img src="../images/index.gif" alt="Index" /></a> 260 <a href="../"><img src="../images/home.gif" alt="Home" /></a> 261 262 </body> 263</html> 264 265