Setting Expires HTTP header on server response through Apache

13 / Sep / 2010 by Tarun Pareek 1 comments

In recent poc, i have set the expires HTTP header on server response for one of the project, such that it will again set when access by user for the specified period, if header is expired already.
The module that control it is “mod_expires.c”. This module is not enabled by default.
You need to enable it by following command (You need to be sudo user):

a2enmod {module name} //here module name is "expires"

Then, open your site configuration file available at apache2/sites-available/{your site}

Append following xml entries in your site configuration file :

          ExpiresActive On
          ExpiresDefault "access plus 2 days"

ExpiresDefault Syntax :

ExpiresDefault "{base} [plus] {num  type}*"

Note : Here base is : ‘access’ and the type is : ‘years’, ‘months’, ‘weeks’, ‘days’, ‘hours’, ‘minutes’, ‘seconds’

You can also use “ExpiresByType” for setting different expires for different file type instead of “ExpiresDefault”.
Hope this code will help 🙂

Tarun Pareek
Intelligrape Software


comments (1 “Setting Expires HTTP header on server response through Apache”)

Leave a Reply

Your email address will not be published. Required fields are marked *