The Short Answer
Use a 301 redirect if you are permanently moving content to a new URL and want search crawlers to index the new page and drop the old one.
Use a 302 redirect if you are temporarily directing traffic elsewhere (e.g., during site maintenance, regional routing, or A/B testing) and want search engines to keep indexing the original URL.
Caching and Search Considerations
Because 301 redirects are permanent, browsers cache them aggressively. If you set a 301 by mistake, reversing it can be difficult because returning visitors will bypass your server and load the cached target directly.
Conversely, 302 redirects are checked on every visit since browsers are instructed never to cache temporary routing.
