Disable caching with .htaccess

Quick .htaccess snippet to disable browser caching by modifying Cache-Control, Pragma, and Expires headers. Strictly plug-n-play.

Just add the following directives to your site’s root .htaccess file:

# DISABLE CACHING
<IfModule mod_headers.c>
Header set Cache-Control "no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires 0
</IfModule>

No editing required. I use this technique on several of my sites and it works like a charm. You can verify that it works using any number of freely available online tools, and/or any browser extension that displays header/server response.

Updates

Update #1: Here is another line that you can play with:

Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"

Update #2: Here is another technique for caching static resources while optimizing performance (You can customize the list of file types to suit your specific needs)

<FilesMatch "\.(css|flv|gif|htm|html|ico|jpe|jpeg|jpg|js|png|pdf|swf|txt)$">
<IfModule mod_expires.c>
ExpiresActive Off
</IfModule>
<IfModule mod_headers.c>
FileETag None
Header unset ETag
Header unset Pragma
Header unset Cache-Control
Header unset Last-Modified
Header set Pragma "no-cache"
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Expires "Mon, 10 Apr 1972 00:00:00 GMT"
</IfModule>
</FilesMatch>

Дали Ви помогна овој одговор? 40 Корисниците го најдоа ова како корисно

Понудени резултати

500 Internal Server Error

Internal Server Error help, 500 error Internal server errors can be caused by a few different...

Do you provide AwStats?

Yes, we provide AWSTATS most of the servers of bergehost Networks and it is updated automatically...

How to add site on Cloudflare? - Prevent DDoS and SpamBot attack

Signing up for CloudFlare is incredibly easy and takes less than 5 minutes. This article outlines...

How to Block certain IP address?

Web servers can host many different domains on one hosting account under Linux/Apache, and public...

How to change a php.ini value?

We use suPHP in all of our servers. So you can modify your php.ini value very easily! All you...