April 28, 2007
HTTP 301 vs. HTTP 302 Redirects
Sometimes, it is necessary to redirect visitors to another part of a web site or to another domain entirely. There are several reasons for needing to do this:
- You buy a new domain and want to redirect all links from the old domain to the new one in order to maintain link equity. This happens, for example, when companies merge and only one of the previous web sites is to be maintained.
- You need to change the structure of a web site and consequently the old links need to be redirected to the new ones. Typically, this happens when the direction of an enterprise is changed or radically expanded in a manor that was not envisaged by the web development team.
- You want to avoid avoid duplicate content (example.com vs. www.example.com).
- You wish to disguise URLs containing affiliate IDs.
There are two ways in which such scenarios can be handled.
- HTTP 301 Permanent Redirect
- HTTP 302 Temporarily Moved
First of all, it is important to point out that making an incorrect choice can lead to serious penalties in search engines or even worse your side being entirely de-listed.
HTTP 301 Permanent Redirect: An HTTP 301 permanent redirect means that the requested object (an HTML page, image or JavaScript file) has moved to a new location, permanently, i.e. it will never be available at the old location, but always at the new location.
HTTP 302 Temporarily Moved: An HTTP 302, on the other hand, is a temporary redirect, meaning that the requested object has been only temporarily displaced and will again be available at the original location in a short while. However, in the meantime, it is available at the indicated, new location.
Unless you have the unlikely latter case, as a matter of principle, you should avoid HTTP 302 entirely. Whenever you wish to redirect a visitor, you should also do so using an HTTP 301.
Technical implementation for a variety of programming languages is summarized in the blog post Domain Redirects for Apache and IIS in PHP, ASP, ColdFusion, dot NET, ISAPI.
