Your options for fixing this include:Ī simple solution is to issue another redirect back again. If people still have the cached 301 redirect in their browser they will continue to be taken to the target page regardless of whether the source page still has the redirect in place. If you previously issued a 301 redirect but want to un-do that Note that 302 and 307 redirects aren't cached by default by browsers. YMMV, and you may find edge cases where it makes sense for a "permanent" redirect to have a time limit. Issuing a 301 redirect but marking it as non-cacheable is going against the spirit of what a 301 redirect is for, even though it is technically valid. Though, if you don't want your redirect to be permanent, it may be a better option to use a 302 or 307 redirect. You could even add Cache-Control: no-cache so it won't be cached permanently by the browser or Cache-Control: no-store so it can't even be stored in temporary storage by the browser. You can add headers such as Cache-Control: max-age=3600 or Expires: Thu, 16:00:00 GMT to your 301 redirects. The browsers still honor the Cache-Control and Expires headers like with any other response, if they are specified. The logic is that you are specifying a "permanent" redirect and not giving them any other caching instructions, so they'll treat it as if you wanted it indefinitely cached. This indefinite caching is only the default caching by these browsers in the absence of headers that specify otherwise. If you don't want the redirect to be cached In all browsers it is still possible to override this default behavior using caching directives, as described below: It works this way in other browsers including Chrome and the Chromium based Edge, though they don't have an about:cache for inspecting the cache. You can verify this at least in Firefox by going to about:cache and finding it under disk cache. It will be removed from the cache if you manually clear the cache, or if the cache entries are purged to make room for new ones. That is, it will remain cached for as long as the browser's cache can accommodate it. In the absense of cache control directives that specify otherwise, a 301 redirect defaults to being cached without any expiry date. IE10 and Chrome 25 cache, but do not clear on browser restart, so when will they clear?.Firefox 18.0.2, Safari 5.1.7 (on Windows 7), and Opera 12.14 all cache, and clear the cache on browser restart.IE7, IE8, Android 2.3.4 do not cache at all.The headers for the incorrect 301 response would have been like this: HTTP/1.1 301 Moved Permanently Upon investigation, I find that there were no Cache-Control and Expires headers set. I can correct the mistake, but anyone who has visited 1.example in the meantime will have cached the incorrect redirect to 3.example, and so they will not be able to reach either 1.example or 2.example until their cache is cleared. When do IE, Chrome, Firefox and Safari clear their cache of 301s?įor example, if I want to redirect 1.example to 2.example, but I accidentally set it to redirect to 3.example, that is a problem. After a quick test, it seems that Safari clears its cache of 301s when it is restarted, but Firefox does not. I am debugging a problem with a HTTP 301 Permanent Redirect.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |