How To Disable Apache Cache

  1. 1. Open httpd.conf
  2. 2. Disable Apache Cache
  3. 3. Include this file in httpd.conf
  4. 4. Restart Apache server

If Apache cache doesn’t work properly for your website, you need to delete Apache cache or clear Apache cache. If it still doesn’t work, then here’s how to completely disable Apache Cache for your website.

1. Open httpd.conf

Open httpd.conf with your favorite editor, make sure mod_rewrite and mod_headers are loaded.

1
2
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule headers_module modules/mod_headers.so

2. Disable Apache Cache

Create a config file in the directory conf/extra/, for example httpd-cache.conf.

Let’s say you want to disable caching html, js, css files only, then add the following lines to your httpd-cache.conf file.

1
2
3
4
5
6
7
8
9
10
11
#Initialize mod_rewrite
RewriteEngine On
<FilesMatch "\.(html|htm|js|css)$">
FileETag None
<IfModule mod_headers.c>
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 12 Jan 1980 05:00:00 GMT"
</IfModule>
</FilesMatch>

If you want to also stop caching other file types such as pdf, jpg, etc. include them in line #3 above.

3. Include this file in httpd.conf

Include this file in httpd.conf:

1
2
# Disable cache
Include conf/extra/httpd-cache.conf

4. Restart Apache server

Restart Apache server to applay changes.