Control HTTP 301 redirects caching

HTTP redirects should be your tool of choice when you’re reorganizing or renaming key sections of your site on order to keep visitors from hitting a not found page and make search engines update their location and keep their ranking.

However, sometimes you might run into a situation when you need to update a redirect, only to find out that the redirection it’s aggressively cached by your browser (specially Chrome).

So, how can you avoid (or at least, control) the way that redirects are cached?

The answer it’s actually quite simple, and it’s entirely standards-based: using Cache-Control HTTP headers.

So, for instance, you might want to force the browser to revalidate the response using something like:

Cache-Control: public, must-revalidate, proxy-revalidate, max-age=3600
Location: https://newurl.com

You might need to adjust the Cache-Control header to fit your specific needs, and find a good balance between cacheability and the possibility to modify the destination URL.

Remember that 301 redirects are intended to be permanent, and so they’re “meant to last forever”, but if you suspect that some redirection might change, you should add Cache-Control headers, since without them, the redirection might be permanently cached by your users’ browsers.

For more information on how Chromium handles redirections cache, check this bug report.