I know a 301 redirect is for a permanent change, and 302 is for a temporary change.
What code should I use when the page is offline for a number of weeks and in the mean time I am redirecting to the homepage? The page should be back up in a few weeks.
If you want to redirect, it would be 302. If you don't want to redirect, you could send
503 Service unavailable and set a Retry-After header (which should hopefully prevent search engines from coming back before that time).
If you still want the end-user experience to be a redirect to the homepage, you might, with heavy heart, consider adding that to the content of your 503 error page with a
Previous answers suggest that browsers might honour cache and expires headers set on a 301 response, but since that fails-unsafe, I wouldn't rely on it. (The standard says the response is "cacheable unless indicated otherwise"; its definition of 302 Found suggests a 302 that is explicitly cacheable might be cached, but it wouldn't be the first time browsers don't implement what could be read out of the letter of the RFCs.)