问题原文
原帖链接 · Koen Hollander · CC BY-SA 3.0
I have looked on Stack Exchange but didn't find the solution for my problem.
The problem: I have a website and want to become an SEO hero. So, I also need to choose status codes...
I know that there are approximately 2 status codes to trigger a redirect.
- 301 - Moved Permanently
- 302 - Moved Temporarily
The question: Which status code stays longer in the cache and how long would that be approximately?
已采纳解答
原帖链接 · MrWhite · CC BY-SA 3.0
there are approximately 2 status codes to trigger a redirect
More like 5 ... 301, 302, 303, 307 and 308.
See: https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#3xx_Redirection
302 - Moved Temporarily
A 302 should never be cached. Browsers do not ordinarily cache a 302. It is after all "temporary".
301 - Moved Permanently
301s are cached by default. Since this is considered a "permanent" redirect, browsers (and possibly intermediary caches) will cache a 301 "aggressively". Without additional cache control headers there is no clear rule for how long the redirect should be cached - it's browser/cache dependent. But suffice to say, it can be a "long time".
However, you should be able to send the appropriate cache control headers (ie. Cache-Control/max-age and Expires HTTP response headers) with the redirect in order to control the caching behaviour.
Reference:
https://stackoverflow.com/questions/9130422/how-long-do-browsers-cache-http-301s
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
