Overview of Apache module mod_expires
This module controlsExpires
Header content andCache-Control
Headermax-age
Command. The validity period (expiration date) can be set to the last modification time relative to the source file or the client access time.
These HTTP headers indicate the validity and durability of the document to the client. If there is a cache, the document can be read from the cache (except that it has expired) rather than from the server. Next, the client checks the cached copy to see if it expires or fails to determine whether updates must be obtained from the server.
To modifyCache-Control
Headermax-age
(See RFC 2616 section 14.9 ).Header
Command.
Alternate (alternating/rotating) interval (interval) syntax (syntax)
ExpiresDefault
AndExpiresByType
Commands can also be defined in easy-to-understand syntax formats:
ExpiresDefault "<base> [plus] {<num> <type>}*"
ExpiresByType type/encoding "<base> [plus] {<num> <type>}*"
<Base> is one of the following:
access
now
(Equivalent'access
')
modification
plus
The keyword is optional. <Num> must be an integer [can beatoi()
Accepted], <type> is one of the following:
years
months
weeks
days
hours
minutes
seconds
For example, the following three commands indicate that the default validity period of a document is one month:
ExpiresDefault "access plus 1 month"
ExpiresDefault "access plus 4 weeks"
ExpiresDefault "access plus 30 days"
The validity period can be further adjusted by adding the "<num> <type>" clause:
ExpiresByType text/html "access plus 1 month 15 days 2 hours"
ExpiresByType image/gif "modification plus 5 hours 3 minutes"
Note: If you use the settings based on The Last modified Date, the "expires:" header willNoAdded to content that is not from a disk file. This is because the "Last Modified Time" attribute does not exist in the content.
Expiresactive command
Description |
Enable or disable generate"Expires: "And"Cache-Control: "Header Function |
Syntax |
ExpiresActive On|Off |
Scope |
Server config, virtual host, directory,. htaccess |
Overwrite |
Indexes |
Status |
Extension (E) |
Module |
Mod_expires |
This command enables or disables the generation of documents within the scope of its functionExpires
AndCache-Control
Header. If it is setOff
No document is generated for the scope of its function.Expires
AndCache-Control
Header (unless it is rewritten by a lower-level rule, such.htaccess
File ). If it is setOn
AccordingExpiresByType
AndExpiresDefault
The standard of instruction definition is the generation of documents within the scope of its functionExpires
AndCache-Control
Header.
Note that this command is not guaranteedExpires
OrCache-Control
Headers are generated. If the defined standard is not standardized, the two headers will not be generated, and the effect is as if this command has never been set.
Expiresbytype command
Description |
Configured by the MIME typeExpires Header Value |
Syntax |
ExpiresByType MIME-type <code>seconds |
Scope |
Server config, virtual host, directory,. htaccess |
Overwrite |
Indexes |
Status |
Extension (E) |
Module |
Mod_expires |
This command defines a document for the specified MIME type (for exampletext/html
) GeneratedExpires
Header Value andCache-Control
Headermax-age
Command.SecondsThe parameter sets the number of seconds that are added to the benchmark time to construct the validity period.Cache-Control: max-age
Is calculated from the validity period minus the current request time and converted to seconds.
The reference time can be the last modification time of the source file or the time when the client accesses the source file.<code>
. "M
"Indicates the last modification time of the source file ,"A
"Indicates the time when the client accesses the source file. Note that<code>
Andseconds
There is no space between them.
The differences between the two benchmarks are subtle. If"M
", All copies of the document in the current cache will expire at the same time, which may be good for regularly updated URLs (such as weekly announcements located at the same location. If"A
", The validity period of each client is different, which may be very good for those image files that are hardly updated, especially for a group of documents that reference the same image.
Example:
# Enable validity period Control
Expiresactive on
# GIF is valid for 1 month
Expiresbytype image/GIF a2592000
# The validity period of the HTML document is one week after the last modification time
Expiresbytype text/html m604800
Note that this command is only available in"ExpiresActive On
. ItOnlyRewrite the specified mime-type documentExpiresDefault
The validity period set by the command.
You can also use the alternate syntax described earlier to specify the validity period.
Expiresdefault command
Description |
Calculation Method of default Validity Period |
Syntax |
ExpiresDefault <code>seconds |
Scope |
Server config, virtual host, directory,. htaccess |
Overwrite |
Indexes |
Status |
Extension (E) |
Module |
Mod_expires |
This command sets the calculation method for the default Validity Period of all documents within the scope of its function. It can beExpiresByType
The command is rewritten based on the MIME type. For more information, seeExpiresByType
Description of the command and the alternate syntax.
XAMPP enable cache (1)