cachinghttp-redirecthttp-status-code-301no-cachehttp-status-code-307

Avoiding 301 redirect caching


This is a follow up question to Using 301/303/307 redirects for dynamic short urls, where I try to determine the best method for implementing short url redirection when the destination url will change on a frequent basis.

While it seems that 301 and 307 redirects both perform the same way, the issue that concerns me is 301 redirect caching (as documented here)- is the best way to avoid this to use 307 redirects instead (I'm assuming 307 redirects will never cache?), or to explicitly send a no-cache header ("Cache-Control: no-cache, must-revalidate")?


Solution

  • Don't try to avoid 301 caching. If you don't want any user agent to cache your redirect, then simply don't use a 301 redirect. In other words, 301 caching is here to stay, and semantically, it's a permanent redirect, so if you're planning to change the destination URL, 301 is not the right status code to use. On the other hand, 307 responses are not cached by default.