mod_expiresmod_expires overviewmod_expires module is responsible for setting of the Expires HTTP header and max-age directive of Cache-Control HTTP header in server responses. The expiration date can be set to relative to the time the source file was last modified or to the time of the client access. Above HTTP headers inform the user about the document's validity and persistence. If cached, the document may be taken from cache rather than from source until this time has expired. After that the copy in cache is considered "expired" and therefore invalid, and a new copy must be received from the source. To modify Cache-Control directives other than max-age you may use the Header directive. Alternate Interval SyntaxExpiresDefault and ExpiresByType directives may be defined using more convenient syntax:
where <base> is one of the following:
The plus keyword is optional. <num> is an integer value and <type> is one of the following: years, months, weeks, days, hours, minutes, seconds. For example, any of the following directives can be used to make documents expire 1 month after being accessed, by default:
The expiry time can be set more precisely by using several '<num> <type>' clauses:
Note! If you want to set Expires header relative to modification date, it will not be set for the content that does not come from a file on disk because there is no modification time for such content. mod_expires directivesExpiresActive
ExpiresActive directive enables or disables the generation of Expires and Cache-Control headers for specific location (e.g. if directive is found inside .htaccess file, it will be applied only to documents generated from that directory). If set to off, the headers will not be generated for any documents inside specific location (unless it is overridden at lower level, e.g. .htaccess overrides server config file). If set to on, the headers will be added to processed documents according to the criteria defined by the ExpiresByType and ExpiresDefault directives. Note! ExpiresActive directive does not guarantee that Expires or Cache-Control header will be generated. If the criteria aren't met, no header will be sent and the effect will be as though the directive was not specified. ExpiresByType
ExpiresByType directive defines the value of Expires header and max-age directive of Cache-Control header generated for documents of the specified type (e.g., text/html). The second argument sets the number of seconds that will be added to the base time to make upthe expiration date. Cache-Control: max-age is calculated by subtracting the request time from the expiration date and converting the result to seconds. Mime-type parameter may be defined as a regular expression (notice that Apache does not support this feature). Base time is either the last modification time for the file, or the time of the client's access to the document. Which of them should be used is specified in <code> field; M stands for file's last modification time and A stands for client's access time. If M value is used, all current copies of the document in all caches will expire at the same time. If A value is used, the expiration date will be different for each client. Example:
Note! This directive will only have effect if ExpiresActive On has been specified. It overrides, for the specified MIME type only, any expiration date set by the ExpiresDefault directive. ExpiresDefault
ExpiresDefault directive sets the default algorithm for calculating the expiration time for all documents in the affected location (that depends on the location of the directive). It can be overridden on a type-by-type basis by ExpiresByType directive.
|