How to add Expires Headers for caching files

We've had many users asking about compressing their website using mod_gzip or mod_deflate and then also wanting the Expires Headers enabled on their sites. "mod_deflate" is enabled on all our servers by default.  It's a critical part to helping to speed websites on the internet.

Caching of files, however, is something that we do not enable by default as each user sets and requires caching differently. To enable the expires headers you'll need to copy the following in green and enter it into your .htaccess file in your site:

Header unset ETag
FileETag None
ExpiresActive On

#3 months

Header set Cache-Control "max-age=7776000"

#WEEK

Header set Cache-Control "max-age=604800"

#DAY

Header set Cache-Control "max-age=86400"

As you can see from the above we have a few different cache-control times. Our Images are all set with a maximum age of 7776000 seconds wihich equals 3 months.  You can change the time to be longer or shorter for any of the extensions. If you have more extensions to add, you can just add them to the end of one of the lines or create a whole new FilesMatch section for your own extension and time setting.

 

For reference, here's a handy .htaccess expiration cheat sheet which you can use to manipulate the various cache expiration times. If you are unsure about the advanced expiration settings below, feel free to open a help desk ticket to our support staff for assistance.

.htaccess Time Cheatsheet

# TIME CHEAT SHEET

#      300   5 MIN
#      600  10 MIN
#      900  15 MIN
#     1800  30 MIN
#     2700  45 MIN

#     3600   1 HR
#     7200   2 HR
#    10800   3 HR
#    14400   4 HR
#    18000   5 HR
#    36000  10 HR
#    39600  11 HR
#    43200  12 HR
#    46800  13 HR
#    50400  14 HR
#    54000  15 HR
#    86400  24 HR

#    86400   1 DAY
#   172800   2 DAY
#   259200   3 DAY
#   345600   4 DAY
#   432000   5 DAY
#   518400   6 DAY
#   604800   7 DAY

#   604800   1 WEEK
#  1209600   2 WEEK
#  1814400   3 WEEK
#  2419200   4 WEEK

#  2419200   1 MONTH
#  4838400   2 MONTH
#  7257600   3 MONTH
#  9676800   4 MONTH
# 12096000   5 MONTH
# 14515200   6 MONTH
# 16934400   7 MONTH
# 19353600   8 MONTH
# 21772800   9 MONTH
# 24192000  10 MONTH
# 26611200  11 MONTH
# 29030400  12 MONTH

If you have any questions, please contact us at https://www.totalserversolutions.com/login.php and any of our staff will be happy to help you out.

Reviewed - 12/22/2016

  • Email, SSL
  • 10 Users Found This Useful
Was this answer helpful?

Related Articles

How do I redirect a page or folder?

I have removed a file from being on the website and would like to forward people who were looking...

301 Redirect for All Domains

So you've purchased a ton of domains to park on your main account, but you don't want Google to...

301 Redirect from non-www to www -- Without Looping!

So - you want to improve your search engine rankings, and SEO gurus told you that Google might be...

Hotlink protecting image.php and GD images

So you've enabled Cpanel's hotlink protection, but those bandwidth thieves are still attacking...

How to block an IP number

A user is accessing our website and we'd like to block this user as they continue to submit fraud...