Search code examples
phpapachemod-expires

Apache: How to add Expires headers to files without mod_expires installed


I'm on a shared host running Apache. Apparently mod_expires is not installed. Is there another way to add expires headers to css-files, images etc. on that environment?


Solution

  • In your .htaccess (if that's an option) you can use a <FilesMatch> block with Header directives. This requires mod_headers, though, and I'm pretty sure that you can't specify a "rolling" expiration date (i.e., "one year from now"). Therefore, you'll need to edit this setting, say, once a year1.

    Also, did you see this question?


    1) Apparently you should refrain from setting the Expires to more than a year into the future: "Do not set it [the Expires header] to more than one year in the future, as that violates the RFC guidelines." (source: Optimize caching)