Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid browser redirect caching

It's not the fist time that i stuck to this problem. Everytime when i use an 301 redirect, the browser caches it. When i change the redirect in my app, i manualy have to clear my browsers cache.

This is not very welcome for an website as you will understand. Is there an solution to avoid this caching?

Currently i got an list of new redirects from my customer. In my .htaccess, i replaced the old ones for the new ones, but it doesn't toke effect.

When i cleared my browser cache, it seems to work propper.

Any solutions? Thanks a lot!

like image 230
George Boot Avatar asked Dec 03 '22 06:12

George Boot


1 Answers

To quote the HTTP specification on the 301 status code:

301 Moved Permanently

The requested resource has been assigned a new permanent URI and any future references to this resource SHOULD use one of the returned URIs. Clients with link editing capabilities ought to automatically re-link references to the Request-URI to one or more of the new references returned by the server, where possible. This response is cacheable unless indicated otherwise.

Hence, the fact that browsers cache the redirected URI shouldn't be a surprise, since it's done as specified.

To get around this problem, most sites use 302 (307 could also be used).

like image 103
Bruno Avatar answered Dec 09 '22 16:12

Bruno