.htaccess is a configuration file for use on web servers running the Apache Web Server software. .htaccess files can be used to alter the configuration of the Apache Web Server software to enable/disable additional functionality and features that the Apache Web Server software has to offer.
Knowing how to configure the .htaccess file allows for better control of assets that are cached. This article will serve as a guide to configure the default headers and well as custom expiry headers to control your caching behavior.
Custom Expiry Headers
When using Origin Pull, there is a default TTL (Expiry Date for the cached files) of 24 hours. There is also the option to override that or set it if not already set on the server. But how do you set a custom expiry header on your server, for a certain file type, using Apache .htaccess (or httpd.conf for advanced users with administrative access to their hosting servers)?
This is fairly easy. One can set an expiry header to a certain file, or a certain file type, or multiple file types to any length desired, and the CDN will honor this header.
ExpiresActive On ExpiresDefault A43200 Header set Cache-Control "no-store, no-cache, must-revalidate, max-age=0" Header set Pragma "no-cache"
In the above example, “testcdn.txt” is our sample file, and “A43200” is our expiry header.
ExpiresActive On <filesmatch "\.(js|css)$"=""> ExpiresDefault A43200 </filesmatch>
- If we want a file to NOT be cached, we will simply set an expiry header to 0 seconds. Example:
ExpiresActive On ExpiresDefault A0 Header set Cache-Control "no-store, no-cache, must-revalidate, max-age=0" Header set Pragma "no-cache"
<filesmatch "\.(js)$"=""> ExpiresDefault A0 Header set Cache-Control "no-store, no-cache, must-revalidate, max-age=0" Header set Pragma "no-cache" </filesmatch>
If you have any questions or experience any issues, please reach out to the Support Team, live chat and ticket support are available 24/7.