Understanding mod_expires apache module [closed]

Working with htaccess is a new capitol for me. I have already read about mod_expires here https://httpd.apache.org/docs/current/mod/mod_expires.htm, but I’m stil confused.

I have the next code from stack overflow:

ExpiresActive On ExpiresByType image/jpg "access 1 year" ExpiresByType image/jpeg "access 1 year" ExpiresByType image/gif "access 1 year" ExpiresByType image/png "access 1 year" ExpiresByType text/css "access 1 month" ExpiresByType text/html "access 1 month" ExpiresByType application/pdf "access 1 month" ExpiresByType text/x-javascript "access 1 month" ExpiresByType image/x-icon "access 1 year" ExpiresDefault "access plus 2 months" 

My questions are:

  1. I suppose the line ExpiresByType image/jpg "access 1 year" tells the client (browser) to download the file and keep it for one year. And when the client accesses the same page from my website, the jpg image won’t be downloaded from my website. It will be read from his computer (where the browser saved first time). After one year, the browser automatically deletes the file and, once the client access my website, it will download again, for another year. If the client cleans his browser history after 2 months, then the browser will download it again even if a year hasn’t passed. Do I miss something ?

  2. What cache availability should I set for each file type ? It depends on the file ? What should I consider when set the expiration time ?

  3. What’s the difference between "access 1 year" and "access plus 1 year" ?

  4. Does ExpiresDefault rule works for php files too ? I mean, if I have a contact.php file with some content and I modify the content of contact.php, because of ExpiresDefault rule, the content won’t change to the user ?

  5. Do search engine spiders listen for this cache rules or they download the files each time they crawling my website ?

  6. Is it true that ExpiresDefault is for the files I don’t set using ExpiresByType ? If the answer is yes, what are the other types ? What types of files are included here ?

  7. Do I understand correct that Header set Cache-Control "max-age=290304000, public" is the maximum time allowed for a file to be cached ? If the answer is yes, then means that "access 999 years" will take no effect as long 290304000 is the limit. True or false ?

Apache mod_expires not setting correct expires datetime

I’m having a problem with mod_expires. I simply set have a default expires of 1 days and then I set the expires by type (for images and audio).

So for example i set ExpiresByType image/jpeg “access plus 1 months”. The problem is that every page has the correct Expires DateTime so it has expires plus 1 days but images and audio (image/jpeg, image/png, audio/mpeg) have an expires of 12 hours. This is my configuration:

<IfModule mod_cache_disk.c>   CacheRoot /var/cache/apache2/mod_cache_disk    CacheDirLevels 2   CacheDirLength 1 </IfModule>   ....     CacheQuickHandler off      CacheLock on     CacheLockPath /tmp/mod_cache-lock     CacheLockMaxAge 5      CacheIgnoreHeaders Set-Cookie     <Location />         CacheEnable disk         CacheHeader on          CacheDefaultExpire 600         CacheMaxExpire 86400         CacheLastModifiedFactor 0.5          ExpiresActive on         ExpiresDefault "access plus 1 days"         ExpiresByType image/jpeg "access plus 1 months"         ExpiresByType image/png "access plus 1 months"         ExpiresByType audio/mpeg "access plus 1 months"         Header merge Cache-Control public         FileETag All     </Location> .... 

I then try to add another Location and do not use ExpiresByType but still without success. This is what I try:

<LocationMatch "(.png|.mp3|.jpg|.jpeg)">          ExpiresActive on          Header Set Cache-Control "max-age=1678400"          ExpiresDefault "access plus 1 days"          FileETag All </LocationMatch> 

The Cache-Control header has the correct max-age but the expires date is still to 12 hours.

I then try to set it manually so I try something like:

Header Set Expires "Thu, 1 Jan 2020 00:00:00 GMT" 

And well that’s working but I need to set it to 1 months/years from the last access.

Apache only do a proxypass to a gunicorn web server that actually serve the current application.