Enable Browser Caching for Apache on Centos

apache-2.2cachecentos6

I am having an issue trying to get browser caching enabled for a website which is served by Apache on a Centos server.

I have done all the usual steps which have worked for me before with Ubuntu installations so at this point I am a bit stumped. I have been googling around but have yet to find a reason why they might require different setups on Centos to Ubuntu. Might be worth mentioning that mod_deflate works fine, any help would be greatly appreciated.

Centos Version

rpm -q centos-release
centos-release-6-9.el6.12.3.x86_64

Apache Version

rpm -q httpd
httpd-2.2.15-59.el6.centos.x86_64

No AllowOveride None's in httpd.conf

grep 'AllowOverride' httpd.conf
AllowOverride All
# AllowOverride controls what directives may be placed in .htaccess files.
AllowOverride All
#    AllowOverride FileInfo AuthConfig Limit
# for additional configuration directives.  See also the AllowOverride
AllowOverride All
AllowOverride All
AllowOverride All

No AllowOverride None's in website VHost.conf

grep 'AllowOverride' /etc/httpd/conf.d/website-in-question.com.conf
AllowOverride All 

Modules are enabled

apachectl -M | grep expires
expires_module (shared)
Syntax OK
apachectl -M | grep headers
headers_module (shared)
Syntax OK

.htaccess content:

#SERVER COMPRESSION
<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/html
  AddOutputFilterByType DEFLATE text/css
  AddOutputFilterByType DEFLATE text/javascript
  AddOutputFilterByType DEFLATE text/xml
  AddOutputFilterByType DEFLATE text/plain
  AddOutputFilterByType DEFLATE image/x-icon
  AddOutputFilterByType DEFLATE image/svg+xml
  AddOutputFilterByType DEFLATE application/rss+xml
  AddOutputFilterByType DEFLATE application/javascript
  AddOutputFilterByType DEFLATE application/x-javascript
  AddOutputFilterByType DEFLATE application/xml
  AddOutputFilterByType DEFLATE application/xhtml+xml
  AddOutputFilterByType DEFLATE application/x-font
  AddOutputFilterByType DEFLATE application/x-font-truetype
  AddOutputFilterByType DEFLATE application/x-font-ttf
  AddOutputFilterByType DEFLATE application/x-font-otf
  AddOutputFilterByType DEFLATE application/x-font-opentype
  AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
  AddOutputFilterByType DEFLATE font/ttf
  AddOutputFilterByType DEFLATE font/otf
  AddOutputFilterByType DEFLATE font/opentype

# For Olders Browsers Which Can't Handle Compression
  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4\.0[678] no-gzip
  BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>

## EXPIRES CACHING ##
<IfModule mod_expires.c>
 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 image/svg "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 application/x-shockwave-flash "access 1 month"
 ExpiresByType image/x-icon "access 1 year"
 ExpiresDefault "access 1 month"
</IfModule>

<ifModule mod_headers.c>

 Header set Connection keep-alive

 <filesMatch ".(css|jpg|jpeg|png|gif|js|ico|svg)$">
  Header set Cache-Control "max-age=60, public"
 </filesMatch>

</ifModule>

Best Answer

Turns out if I removed the following lines from .htaccess it will work:

 <filesMatch ".(css|jpg|jpeg|png|gif|js|ico|svg)$">
  Header set Cache-Control "max-age=60, public"
 </filesMatch>

Feel like a bit of an idiot now but hey ho at least its working!