HTTP response Status Codes 301 and 302

Source: Internet
Author: User
Tags response code

The difference between 301 and 302 in the HTTP return code(2012-10-15 22:06:09) reproduced
Tags: gossip Category: Front page control

A Official statement

301,302 is the encoding of the HTTP state, which means that a URL has been shifted, except that:

301 redirect:301 Represents a permanent transfer (permanently Moved).

302 redirect:302 represents a temporary transfer (temporarily Moved).

This is a very official statement, so what is the difference between them?

Two The difference in reality

2.1. for user

301,302 is no different to the user, they see the effect is just a jump, the old URL in the browser becomes the new URL. The page jumps to the place where this new URL points.

2.2. for engines and webmasters

2.2.1 302

302 The steering may have URL normalization and URL hijacking issues. May be judged by search engines as a suspicious turn, or even as cheating.

URL Normalization

See also: http://www.chinamyhosting.com/seoblog/2006/04/10/url-canonicalization/

URL Hijacking

What does 302 redirect and URL hijacking (URL hijacking) matter? This is going to start with how the search engine handles 302 turns. From the definition of a 302 redirect to URL b from URL A, the host server implies that URL a may change its mind at any time, re-display its own content or move to another place. Most of the search engines in most cases, when received 302 redirect, generally as long as to crawl the destination URL, that is, url B.

In fact, if the search engine encountered 302 turn, 100% of the target URL b crawl, you do not have to worry about URL hijacking.

The problem is that sometimes search engines, especially Google, don't always crawl the target URLs. Why is it? For example, sometimes a URL is very short, but it does a 302 redirect to the B URL, and the B URL is a long, messy URL, and may even contain some questions such as question marks. Naturally, a Web site is more user-friendly, while the B URL is both ugly and user-friendly. It is likely that Google will still show URL a.

Because the search engine ranking algorithm is only a program and not a person, in the face of 302 redirects, and can not be like a person to determine exactly which URL is more appropriate, which resulted in URL hijacking the possibility. That is, an immoral person in his own URL A to do a 302 redirect to your URL B, for some reason, Google search results are still displayed in URL a, but the content of the Web page is your URL B is the content, this is called URL hijacking. Your hard-earned content was stolen by someone else.

2.2.2 301

When page A is redirected to page B with a 301 redirect, the search engine can confirm that page a permanently changes position, or that it does not exist, and that the search engine will treat page B as the only valid target.

The 301 benefits are:

First, there is no URL normalization issue.

Second, it is also important that page A's PR page level will be uploaded to page b.

Three Implemented in Apache 301, 302

Method one, URL Rewrite,mod_rewrite

Rewriteengine on

Rewritecond%{http_host} ^cmp.soso.com [NC]

Rewriterule ^/js/(. *) http://www.soso.com/js/$1 [r=301]

ServerName cmp.soso.com

Redirect All Access under the JS directory in cmp.soso.com to http://www.soso.com/js/, specifying a jump return code of 301.

For an explanation of [r=301]:

' Redirect| R [=code] ' (forced redirection redirect)
A substitution that is prefixed with http://thishost[:thisport]/(making the new URL a URI) can be forced to perform an external redirect. If code is not specified, an HTTP response code of 302 (temporary move) is generated. If you need to use a different response code in the range of 300-400, you can specify this value here, plus one of the following symbol names: Temp (default), permanent, seeother. It can be used to feedback the normalized URL to the client, such as rewriting "/~" to "/u/", or/u/user plus slashes, etc.

Note: When using this tag, you must ensure that the replacement field is a valid url! Otherwise, it will point to an invalid location! And keep in mind that this tag itself is just a prefix to the URL plus http://thishost[:thisport]/, and the rewrite operation will still continue. In general, you will want to stop the rewrite operation and immediately redirect, then you also need to use the ' L ' tag.

Method two Redirect, involving modules: Mod_alias

Cases:

documentroot/home/qmhball/web/mybranches/stat_3276/oa/

ServerName oalogin.com

Redirect 301/login.php http://www.soso.com

REDIRECT access to login.php under Oalogin.com to http://www.soso.com, return code 301.

If you do not specify a return value for redirect (301 in the previous example), the default redirect is "temporary" (HTTP status 302).

Reference:

1.rfc2616

10.3.2 301 Moved Permanently

10.3.3 302 Moved temporarily

2. Page jumps from HTTP status 301,302,200

Http://blog.joycode.com/ghj/archive/2007/09/21/108696.aspx

3. 301 Redirection and 302 redirect Redirection in HTTP

Http://blog.csdn.net/xuhui_7810/archive/2009/03/06/3962603.aspx

4. Apache Handbook

(Transfer from http://blog.163.com/[email protected]/blog/static/131774484201221495129735/)

HTTP response Status Codes 301 and 302

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.