Official statement
301 Moved Permanently
#This and all future requests should be directed to the given URI.[23]
302 Found
#This is an example of industry practice contradicting the standard. The HTTP/1.0
Specification (RFC 1945) required the client to perform a temporary redirect (the
Original describing phrase was "Moved Temporarily"),[24] but popular browsers
Implemented 302 with the functionality of a 303 See Other.
Added status codes 303 and 307 to distinguish between the two behaviours.[25]
However, some Web applications and frameworks use the 302 status code as if
It were the 303.
To put it simply:
Both 301 and 302 are numeric codes in which the Web server responds to HTTP protocol request status
The difference between the two
1) for user
301 and 302 No difference, is the browser inside the URL jumps into a new URL address
2) for search engines
There is a URL hijacking problem
650) this.width=650; "src=" Http://www.lichengbing.cn/ueditor/php/upload/image/20160806/1470418533822900.png "alt= "URL hijacking. png"/>
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 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 others.
Nginx Configuration 301 302
1) rewrite the URL address using the rewrite function of the server
Vim www.conf
Server {
Listen 80;
Server_name lichengbing.com;
Location / {
#rewrite ^/(.*) http://www.lichengbing.cn/$1 permanent;#301 Permanent Jump
Rewrite ^/(.*) http://www.lichengbing.cn/$1 redirect;#302 temporary jump
}
}
Server {
Listen 80;
Server_name www.lichengbing.com;
Location / {
Root html/www;
Index index.html index.htm;
}
Access_log logs/access_www.log main;
}
2) We use the Curl command to simulate access, get the HTTP status code
[root@db02 ~]# curl -I http://lichengbing.com
HTTP/1.1 302 Moved Temporarily #302 Status Code
Server: nginx/1.6.3
Date: Fri, 05 Aug 2016 17:11:43 GMT
Content-Type: text/html
Content-Length: 160
Connection: keep-alive
Location: http://www.lichengbing.cn/ #change address
Website Monitoring 302 Issues
Usually we use a script to monitor the Web server like to monitor the status code, 200, 301, 302 is normal, but there are special circumstances, such as:
[root@db02 ~]# curl -I -s -o /dev/null -w "%{http_code}\n" http://lichengbingg.com
302 #lichengbingg.com does not exist (302 FOUND)
[root@db02 ~]# curl -I -s -o /dev/null -w "%{http_code}\n" http://taobao.com
302 #taobao.com Existence (302 Moved)
So, either monitor the Web server port or delete the 302
#if [ "`nc -w 5 $url $Port &&echo ok`" = "ok" ];then
#if [ "`echo -e ‘\n‘|telnet $url $Port|grep Connected|wc -l`" = "1" ];then
#if [ "`nmap $url -p $Port|grep open|wc -l`" = "1" ];then
#if [ "`curl -I http://$url 2>/dev/null|head -1|egrep "200|301"|wc -l`" = "1" ];then
#if [ "`curl -I -s -o /dev/null -w ‘%{http_code}\n‘ http://$url`" = "200" ];then
Zabbix monitoring more worry.
HTTP returns the difference between 301 and 302 in the status code