In this post I will describe the different ways of redirecting using the HTTP protocol. It is a shorter version of a previous blog post of mine that I made.
In short you can use the following list on how redirects work:
- 301 - Redirects permanently and may not make the exact same request on the redirected resource
- 302 - Redirects temporarily and may not make the exact same request on the redirected resource
- 307 - Redirects temporarily and should make the exact same request on the redirected resource
- 308 - Redirects permanently and should make the exact same request on the redirected resource
Permanent redirects may cause search engines to cache the redirect and never index the original page again but only index what is redirected to. Temporary redirects are not cached as they are.. Temporary. Therefore permanent redirects are more powerful and "dangerous" if done wrong. You could use a temporary redirect if your site or service is temporarily down and a use case for permanent redirects could for example be if you are moving to another domain.
"May not make the exact same request" in the above refers to such parts of the request as the HTTP verb. If you redirect using a 301 or 302 your client might request the resource redirected to using a GET, even if the original was POST, PUT, DELETE or whicher verb. Using 307/308 the request should be the same for the resource redirected to, however this is of course up to the client. Older browsers or clients may not handle it correctly.
If you want my full explanation please take a look at my post How to redirect HTTP put, post or delete requests which has more details. I hope you enjoyed this shorter version, let me know in the comments below what you think :)