In this article, I am going to explain the major role of 404, 301 and 302 HTTP status code. How can they used to transfer the index to other page or remove from search engine’s index?
Google bot and other search engine understands your website or web page’s status by the HTTP status code you return.
If some unwanted page of your website is indexed in Google, you can return 404-status code for that page. The page will be removed from index eventually. Of course, you can remove from Webmaster tool. But setting 404-status is easy when you have large number of spam pages indexed.
302 is the most common way of URL redirection. That indicates the search engine that the URL is temporarily moved to some other page. That does not change the index in Google, just redirects.
301 can be used when you want to transfer the index of your domain or page to a new domain or new page. That indicates the search engines that the page or site is permanently moved to some other domain.
301 HTTP status code is useful if you plan to move your already indexed site to a new domain or when you change your page URL. In this case the old URL or old domain must return 301 HTTP status.
Hope this helped.