The example above is one of two common ways for Apache to communicate with the browsers to “hold on to certain files longer” assuming they have the cache space available.
This method uses the
mod_expires Apache module. This module controls the setting of the Expires HTTP header and the max-age directive of the Cache-Control HTTP header in server responses. They can set the expiration date to be relative to either the time the source file was last modified, or to the time of the client access.
# BEGIN Expire headers
# Turn on the module.
ExpiresByType text/css “access plus 1 month”
# END Expire headers
The other method is Caching with the
mod_header module of Apache. Here is a sample setting a one month max-age for certain files that match(.js and .css):
# BEGIN mod headers
# Turn on Expires
Header set Cache-Control “max-age=2419200”
# END mod headers
Both methods work, I find the first method
mod_expires easier to set up and understand. But you may prefer the latter.
Both examples the first few statements make sure we are processing the correct modules
ExpiresActive on makes sure that the ExpiresActive Module is turned on.
ExpiresByType text/css “access plus 1 month” Set the expiration date documents of the specified content -type (e.g., text/html) based on this “access” plus 1 month. You can also set it up to use
modification instead of
access, if you want the cache rules based on modification date.
You can use any of the following time “types”
You can also turn off caching for a type by specifying `` ExpiresByType text/css “now”`.
This uses RegEx(regular expressions) to match files by the files extension in a
FilesMatch block. It then sets the cache in seconds with a
In Apache there are almost an unlimited way of doing many things.