Httpcode 301 is the same as httpCode 302. 301 is a permanent redirect and 302 is a temporary redirect. And if you answer that, the interviewer will silently deduct one point. To continue, what are the other differences? The following small make up for you to say the difference between the two in detail.
Definition 1.
301: The requested resource has been permanently moved to the new location, and any future references to this resource should use one of the urIs returned by this response. If possible, clients with link editing capabilities should automatically change the requested address to the one that is returned from the server. Unless otherwise specified, the response is also cacheable.
302: The requested resource now temporarily responds to the request from a different URI. Since such redirects are temporary, the client should continue to send future requests to the original address. The response is cacheable only if specified in cache-Control or Expires.
Both are POST requests that are turned into GET requests by the browser after 301/302
2. The cache
As defined, browsers default to a long cache for 301 requests. 302 is not cached.
3. Search engines
301: The resource at the old address A is no longer accessible (permanently removed). Redirect to site B. The search engine will grab the content of site B and save the site as site B.
302: The resource of old address A is still accessible, this redirection is only A temporary jump from old address A to ADDRESS B, then the search engine will grab the content of B, but will save the URL as A.
4. Security
Try to use 301 jump to prevent url hijacking!
Suppose A -> B. Most search engines in most cases, when receiving 302 redirects, sometimes search engines, especially Google, do not always fetch the target url. For example, sometimes URL A is short, but it does A 302 redirect to URL B, which is A long, messy URL that may even contain A question mark or something like that. Naturally, SITE A is more user-friendly, while site B is ugly and not user-friendly. Google will most likely still show url A. Because the search engine ranking algorithm is only a program rather than a person, in the encounter 302 redirect, and can not be as accurate as a person to determine which site is more appropriate, which causes the possibility of URL hijacking. That is, if an unscrupulous person makes A 302 redirect from his own web site A to your web site B, and for some reason Google’s search results still show web site A, but the content is from your web site B, this situation is called URL hijacking. What you worked so hard to write has just been stolen. URL hijacking caused by 302 redirects has been around for some time. But so far, there seems to be no better solution. The 302 redirection issue is also being addressed in the ongoing Google Big Daddy data center conversion. According to some search results, url hijacking has improved, but not completely.
To put it simply: a bad guy transfers his phone calls to a celebrity, making everyone think his phone belongs to the celebrity. After his mobile phone number becomes famous, he can set up a wechat group, boldly pretend to be a star, realize his Micro Shang dream, and walk on the peak of his life from now on.