36

We are moving a site from one CMS to another. The .htaccess file has been changed and it needs to be refreshed for the new site to work right. From what I understand the .htaccess file will only be refreshed if the browser cache is cleared? It is fine for those creating the site to clear our cache, but is there a way to get the users' browsers to get the new .htaccess file without the user clearing cache manually on his own initiative?

Johann Dyck
  • 613
  • 1
  • 6
  • 13
  • 3
    Browsers do not access the .htaccess file. This is used by apache to determine which files to serve for requests. It is not used by the browser at all. – Ben Parsons Feb 03 '12 at 09:20
  • 1
    .htaccess file has nothing to do with browsers cache. don't worry – machineaddict Feb 03 '12 at 09:20
  • Does any of the information like redirects or anything like that go from the file to cache? Why would a browser that has visited the site be redirected like the old .htaccess file indicates? Just a fluke? – Johann Dyck Feb 03 '12 at 10:35
  • 1
    Yes, I think the browser may cache the redirect response of website (but usually not for a long time). You should only use HTTP 302 redirects (temporary) and not HTTP 301 (permanent) in your SEO. Or better, now redirect with 301 all old URLs to the new ones. – Marki555 Feb 03 '12 at 13:28
  • Yeah, setting up a new redirect (that wouldn't be needed on a fresh site) made my browser forget the old redirect. Thanks, Marki555. – Johann Dyck Feb 04 '12 at 08:35
  • 2
    Thanks, I also had the problem and clearing my browser cache solved it. Thank you very much, I was turning crazy ! – beluga Feb 28 '13 at 14:46
  • I'm a tad confused then. With our hosting environment changing the htaccess file will result in the changes only being visible in a different browser (for a given period of time, like with any cached content) - so clearly the browser does do some kind of caching, else viewing the content int another browser wouldn't result in different content being served. – Nathan Hornby Oct 23 '14 at 14:39

4 Answers4

28

If you're using RewriteRule, just use R instead of R=301. For other purposes, you'll have to clear your browser cache whenever you change a redirect.

from https://stackoverflow.com/a/7749784/1066234

Community
  • 1
  • 1
Avatar
  • 14,622
  • 9
  • 119
  • 198
12

Some servers will reload as soon as you replace the .htaccess file.

If so it instantly be used for all subsequent requests. You do not need to refresh any caches.

Some servers only check htaccess periodically.

Community
  • 1
  • 1
baynezy
  • 6,493
  • 10
  • 48
  • 73
  • 2
    .htaccess is checked by apache on every request (and for each request it checks for htaccess in all subdirs of DocumentRoot, not only the current directory) – Marki555 Feb 03 '12 at 13:26
  • 70
    That's definitely not the case. Some servers only check .htaccess files periodically. – SColvin Apr 23 '13 at 16:45
  • 4
    @SColvin, any idea how to force a server to load an updated .htaccess? – pseudon Aug 31 '15 at 23:42
  • 1
    I have removed http to https redirection code, but it's still redirecting to https, what to do? – Kiran Reddy Mar 06 '17 at 12:29
5

If you already had a R=301 redirect, then you just changed where it redirects to in htaccess, but it isn't updating for you, then it's probably cached in your browser. You can't do a hard refresh on that page because it redirects. You can try in another browser and if it works there, you just need to clear cache in Chrome. Settings > Privacy > Clear browsing data. Then you only need to check "Cached images and files" This will not clear your logins or anything.

Curtis
  • 2,486
  • 5
  • 40
  • 44
2

I had a rewriterule in my .htaccess file like,

 RewriteCond %{HTTPS} !on
 RewriteRule (.*) https://example.com%{REQUEST_URI} [L,R=301] 

and once I opened the site in localhost it never gave me a chance to hard refresh the page.

Solution: I added a random string like localhost/mywebsite/index.php?1234

Mathew
  • 168
  • 2
  • 12