How to add Expires Headers for caching files Print

  • 276

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://mylighthost.com and any of our staff will be happy to help you out.


Was this answer helpful?

« Back