How to Set an Expires Header in Apache
Setting an Expires (or Cache-Control) header in Apache will help speed up your Web site. We’re running Apache 2.x, and define an expires header for all of our static assets (images, stylesheets, and scripts).
Just add the following to your <VirtualHost> section of your Apache configuration:
ExpiresActive On
ExpiresByType image/png “now plus 365 days”
ExpiresByType image/jpeg “now plus 365 days”
ExpiresByType image/gif “now plus 365 days”
ExpiresByType application/javascript “now plus 365 days”
ExpiresByType application/x-javascript “now plus 365 days”
ExpiresByType text/javascript “now plus 365 days”
ExpiresByType text/css “now plus 365 days”
You can read all about expires headers by reading Yahoo!’s Best Practices for Speeding Up Your Website guide.
Also, be sure to check out our post on how to speed up your Website by Configuring Apache to Gzip Your Components.
3 Comments to How to Set an Expires Header in Apache
Leave a Reply
About Justin
Search
Recent Posts
- A Simple Formula for Evaluating Risk
- Not Having a Plan B Makes Plan A More Successful
- Easy Rails API Authentication Using restful-authentication
- God Init.d Script for CentOS
- Private, Authenticated RSS Feeds in Rails
- A Private Web Beta in Seconds with Prefinery
- Backup Your WordPress Blog to Amazon S3 using Ruby
- How to Set an Expires Header in Apache



How do I set expiration date using the Header directive in Apache?
One can do Header set Expires “Thu, 15 Apr 2010 20:00:00 GMT”
but how do you specify something like access plus 1 day ???
how to set expires header for .swf files
Thanks,
Sreeyesh
“…ExpiresActive On
ExpiresByType image/png “now plus 365 days”
ExpiresByType image/jpeg “now plus 365 days”
ExpiresByType image/gif “now plus 365 days”
ExpiresByType application/javascript “now plus 365 days”
ExpiresByType application/x-javascript “now plus 365 days”
ExpiresByType text/javascript “now plus 365 days”
ExpiresByType text/css “now plus 365 days”…”
Could this be placed in mod_headers.c?