.HTACCESS doubts (special mod_expires)

1

I would like to understand better how this module works, in particular I leave as an example what is in the Root folder of one of the sites I manage:

<IfModule mod_expires.c>
ExpiresActive On 
ExpiresDefault "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType text/css "access 1 month"
ExpiresByType application/javascript "access plus 1 year"
</IfModule>
  • the ExpiresDefault defines the default expiration of all items (gif, png, css, js ..)?
  • So in my.htaccess I'm overwriting the default value that was defined above (when I set expire to png, jpeg .. specifically)?
  • If I start the module mod_expires .htaccess in a subfolder, even empty, it overrides what was written in the .htaccess module that Is it in the root folder?
  • It's true that if I use parameters in the URL, I'll be forcing the cache again, for example, this: index.html , be different from that index.html?1234 ?
asked by anonymous 02.11.2015 / 00:12

1 answer

1
  

The ExpiresDefault part defines the default expiration of all items (gif, png, css, js ..)?

  • Not only the gif, jpeg, png, but any page accessed, even the dynamics. However you can use <FilesMatch> to filter the files you want to receive ExpiresDefault , see this example:

    #Qualquer página terá um cache de 1 mês
    ExpiresDefault "access plus 1 month"
    
    #Arquivos que tem extensão como .gif, .jpg, .jpeg e .png terão um cache de 1 ano
    #Sobrescreve o primeiro
    <FilesMatch "\.(?i:gif|jpe?g|png)$">
        ExpiresDefault "access plus 1 year"
    </FilesMatch>
    
  

So in my .htaccess I'm overwriting the default value that was previously set (when I set it to expire for png, jpeg .. specifically)?

  • Yes, ExpiresByType overwrites to the page that uses the specified mimetype.
  

If I start the module mod_expires .htaccess in an empty subfolder, does it overwrite what was written in the .htaccess module in the root folder?

  • Yes, the .htaccess subfolders overwrite the parameters and flags of top-level folders.
  

It's true that if I use parameters in the URL, I'll be forcing it to cache again, for example, this: index.html, be different from index.html? 1234?

  • It's true, because browsers index.html is different from index.html?1234 , since everything that comes after ? is a GET parameter and means that you are looking for something supposedly different, the browser has no way of knowing if index.html is a static or dynamic page, and we usually use ? to define that we are looking for something dynamic. It is very common to use ? to prevent caching of .js and .css .

    See this answer: What is the use and when to use version in .js and .css files?

    p>

    Note that some proxy servers do not interpret ? and therefore in some cases the cache is not ignored.

02.11.2015 / 00:31