Allow to make your web site appear faster (if user visits your site for a second time, static files will be fetched from the browser cache)

1.Login into your server using SSH

2.enable mod_expires

#a2enmod expires

3.Restart Apache

#service apache2 restart

4.Configure mod_expires

a.Using FilesMatch in /var/www/html/

#vi /var/www/html/.htaccess
<IfModule mod_expires.c>
          <FilesMatch "\.(jpe?g|png|gif|js|css)$">
                      ExpiresActive On
                      ExpiresDefault "access plus 3 days"

This would tell browsers to cache .jpg, .jpeg, .png, .gif, .js, and .css files for 3 days

time units in your configuration can be use.

  • years
  • months
  • weeks
  • days
  • hours
  • minutes
  • seconds

5.Restart Apache

#service apache2 restart

Leave a Reply

Your email address will not be published.