Home > Blockchain >  Expiration header for all files in a specific folder (.htaccess)
Expiration header for all files in a specific folder (.htaccess)

Time:10-12

For all files, except pdf, in a specific directory as well as its sub-directories on the server, I would like to set the expiration header to 10 hours. How can I do this in the .htaccess file?

<Directory "/foldername">
   <IfModule mod_expires.c>
      ExpiresActive On
      ExpiresByType * "access plus 10 hours"
   </IfModule>
</Directory>

I understand Directory cannot be used in .htaccess. But how to do this?

CodePudding user response:

You could put the .htaccess into the specific directory, and do it in there without any further restriction. Or use an If condition, to apply this based on what the request URI starts with.

ExpiresByType * won't work, according to the documentation, this needs an actual mime type as "argument".

But ExpiresDefault also exists, and allows you to specify the default expiry for all files.

  • Related