Setting Custom Expiry Headers using .htaccess
When using Origin Pull “Pull Zones” with NetDNA™/MaxCDN™, you get a default TTL (Expiry Date for the cached files) of 24 hours, you get 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).
Setting a default TTL/Expiry Header in .htaccess:
This is fairly easy, you can set an expiry header to a certain file, or a certain file type, or multiple file types to any length desired, and NetDNA™/MaxCDN™ will honor this header.
If you wish to make the TTL of 12 hours for example, that would be 60*60*12 = 43200 seconds.
Example:
ExpiresActive On
<Files testcdn.txt> ExpiresDefault A43200 Header set Cache-Control "no-store, no-cache, must-revalidate, max-age=0" Header set Pragma "no-cache" </Files>
In the above example, “testcdn.txt” is our sample file, and “A43200” is our expiry header.
If we want to do that for all JavaScript files, or CSS files, we use the “FilesMatch” tag and we use a regular expression for the file type.
Example:
ExpiresActive On
<FilesMatch "\.(js)$"> ExpiresDefault A43200 </FilesMatch>
If we want to do that for certain JavaScript files, or CSS files, we use the “FilesMatch” tag and we use a regular expression for the file type.
Example:
ExpiresActive On
<FilesMatch \(file1.js|file2.js|file3.css|file4.ext)$"> ExpiresDefault A43200 </FilesMatch>
If we want to do that for multiple file extensions, we use the “FilesMatch” tag and we use a regular expression for the file type.
Example:
ExpiresActive On
<FilesMatch \.(jpg|jpeg|png|gif|css|js|zip|rar|exe|ttf|eot|svg)$"> 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
<Files testcdn.txt> ExpiresDefault A0 Header set Cache-Control "no-store, no-cache, must-revalidate, max-age=0" Header set Pragma "no-cache" </Files>
Or
<FilesMatch "\.(js)$"> ExpiresDefault A0 Header set Cache-Control "no-store, no-cache, must-revalidate, max-age=0" Header set Pragma "no-cache" </FilesMatch >
Support