htaccess - How to force the client's browser to clear the cache?

htaccess cache-control
htaccess no-cache
htaccess force reload
laravel htaccess cache
htaccess cached
force https htaccess wordpress
cache busting htaccess
dreamhost htaccess cache

For my site I have the following htaccess rules:

# BEGIN Gzip
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript
</IfModule>
# END Gzip

# BEGIN EXPIRES
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresDefault "access plus 10 days"
    ExpiresByType text/css "access plus 1 month"
    ExpiresByType text/plain "access plus 1 month"
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"
    ExpiresByType application/x-javascript "access plus 1 month"
    ExpiresByType application/javascript "access plus 1 month"
    ExpiresByType application/x-icon "access plus 1 year"
</IfModule>
# END EXPIRES

I've just updated my site and it looked all screwy until I cleared my cache. How can I force the client's browser to clear the cache after an update so that the user can see the changes?

You can force browsers to cache something, but

You can't force browsers to clear their cache.

Thus the only (AMAIK) way is to use a new URL for your resources. Something like versioning.

Force your site to load securely with an .htaccess file – DreamHost , Please note that your FTP client must be configured to show hidden files. If not, you will not see the .htaccess file. View the following article for  And to prevent js, css cache, you could use tool to minify and obfuscate the scripts which should generate a random file name every time. That would force the browser to reload them from server too. Hopefully, that helps.

As other answers have said, changing the URL is a good cache busting technique, however it is alot of work to go through a bigger site, change all the URLs and also move the files.

A similar technique is to just add a version parameter to the URL string which is either a random string / number or a version number, and target the changed files only.

For instance if you change your sites CSS and it looks wonky until you do a force refresh, simply add ?ver=1.1 to the CSS import at the head of the file. This to the browser is a different file, but you only need to change the import, not the actual location or name of the file.

e.g:

<link href="assets/css/style.css" rel="stylesheet" type="text/css" />

becomes

<link href="assets/css/style.css?ver=1.1" rel="stylesheet" type="text/css" />

Works great for javascript files also.

How can I cache my site with an .htaccess file? – DreamHost , Creating an .htaccess file on your DreamHost web server View the on how to update it (depending on if you're using an FTP client or SSH):. One of the many functions you can perform via .htaccess is the 301 redirects, which permanently redirects an old URL to a new one. You can activate the feature to force HTTPS on all incoming traffic by following these steps: Go to File Manager in your hosting panel and open .htaccess inside the public_html folder.

I got your problem...

Although we can clear client browser cache completely but you can add some code to your application so that your recent changes reflect to client browser.

In your <head>:

<meta http-equiv="Cache-Control" content="no-cache" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />

Source: http://goo.gl/JojsO

How to force HTTPS using the htaccess file, You can force an HTTPS connection on your website by adding these rules in your website's .htaccess file: The .htaccess file needs to be located inside the. One of the many functions you can perform via .htaccess   is the 301 redirects, which permanently redirects an old URL to a new one. You can activate the feature to force HTTPS on all incoming traffic by following these steps: Go to  File Manager  in your hosting panel and open .htaccess  inside the  public_html  folder.

You can not force the browsers to clear the cache.

Your .html file seems to be re-loaded sooner as it expires after 10 days. What you have to do is to update your .html file and move all your files to a new folder such as version-2/ or append a version identifier to each file such as mypicture-2.jpg. Then you reference these new files in your .html file and the browser will load them again because the location changed.

How to force SSL with .htaccess, The best way to do this is to use directives written in the .htaccess file. As we are using the Apache server there are a couple ways of adding these commands WordPress wp-login.php Brute Force Attack Not a Customer? Your website most likely already has a .htaccess file in the website’s root file directory. If not create a new file in the websites root file directory and name it .htaccess. To force SSL connections using the mod_rewrite module, you would add the following to the website’s root .htaccess file. Make sure to check if there are existing entries for any of the following settings in your .htaccess file to avoid duplicate or conflicting rewrite rules.

You can tell the browser never cache your site by pasting following code in the header

<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />

And to prevent js, css cache, you could use tool to minify and obfuscate the scripts which should generate a random file name every time. That would force the browser to reload them from server too.

Hopefully, that helps.

How to disable caching using the .htaccess file, When implementing redirects in your .htaccess file, be aware of the following best To force all traffic to use both the www domain and SSL (even if not initially  You can activate the feature to force HTTPS on all incoming traffic by following these steps: Go to File Manager in your hosting panel and open .htaccess inside the public_html folder. Scroll down to find RewriteEngine On and insert the following lines of code below it: RewriteEngine On. RewriteCond %{HTTPS} off.

Redirecting visitor requests with the .htaccess file, Just Host supports .htaccess files however as a customer you are responsible for what is in this file and how it changes your site Using your preferred FTP client upload the file to the server. How To Force SSL On All Pages In .htaccess File. But the problem is, with the code above added to .htaccess, for both these re-directs, it will throw a 302 instead of a 301 permanent re-direct. Which is really bad. I used the below code to force my primary http .com domain to https .com, and now both re-directs show up 301.

htaccess Tutorial, @LukasReschke You can already force HTTPs in the config/config.php file. They aren't present anymore since some versions - it was removed in 8.1 owncloud/  It's possible for a visitor to enter in a direct HTTP URL on your WordPress site, even when an SSL certificate is active. To force any HTTP request to redirect to HTTPS, you can add code to your WordPress .htaccess file. There are two code options below for you to use. The first should work as shown, but if not, try option two instead. Option #1

Enforce HTTPS via .htaccess edit · Issue #132 · nextcloud/server , The .htaccess file can also be used to force HTTPS on specific folders. Edvinas mentors and trains every new customer support agent at  The .htaccess file needs to be located inside the site's document root folder. If your website is in a sub folder, then the .htaccess should be placed in the corresponding sub folder. You can create or edit the .htaccess file either via FTP , or using with the File Manager available in cPanel.

Comments
  • Similar problem?: stackoverflow.com/questions/1207492/…
  • You need to change the urls to the resources. e.g. by renaming the folder that contains the resources, or the filename itself. Google cache busting for more info.
  • Here you can find a better solution: stackoverflow.com/questions/118884/…
  • Take a look at this question, i think it can help you: [stackoverflow.com/questions/11532636/… [1]: stackoverflow.com/questions/11532636/…
  • Yup. exactly this. You even say in your htaccess 'don't even bother to contact the server before 10 days are up'.
  • Does the cached url contact the server for changes or it doesnt connect at all when url is loaded even when you are offline completely?
  • This answer is a little dated. Is this still a true statement?
  • @CraigLondon - it's a matter of phrasing...this is still true; however, you can force a browser to refresh its cache on load for your site as shown here: stackoverflow.com/questions/5721704/…
  • simple, easy and the best part it works. Tried before htaccess but simply didn't work...
  • Although the accepted answer states this, this one provides more information. This should be the accepted answer in my opinion.
  • The beauty of stackoverflow is offering potential solutions that may not fill the cookie cutter question by OP but enable him to get a similar result or help people in future like myself