I want to elaborate on the logic of this method. As Tim noted below, this isn't actually the official use of a 301 redirect, which technically is a way for a web server to indicate that a resource has been permanently moved. Likewise, 302 is technically for indicating when a resource has been temporarily moved to a new location.
However, the 301/302 response codes have a history of being appropriated for other uses by browsers, by search engines and by developers. For example, before 303 existed, it was common to use a 302 redirect to respond to POST requests when you wanted to redirect the user to another page (ie. to prevent a page refresh resubmitting the form). This was technically not what a 302 is supposed to be used for, but due to the lack of alternatives, it was still standard practice to use 302 in this way. Today we have 303, so 302 redirects should no longer be used for this type of redirection, though many applications still do.
Another common nonstandard use of 301/302 redirects is for URL shortening. It's widely recommended for SEO purposes that, if you need to shorten a URL, you use a service that performs a 301 redirect. But technically the content hasn't been moved from the shortened URL to the destination; the shortened URL is just a new alias for it.
- Using the 301 redirection method doesn't conform with the official use of 301 laid out in the HTTP specs.