Differences between 301 and 302 in HTTP return Status Codes
Official statement
List of HTTP status codes
301 Moved Permanently
# This and all future requests shocould 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 (
Original describing phrase was "Moved Temporarily"), [24] but popular browsers
Implemented 302 with the functionality of a 303 See Other. Therefore, HTTP/1.1
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.
Simply put:
Both 301 and 302 are digital codes used by web servers to respond to HTTP request statuses.
301 represents permanent transfer (Permanently Moved)
302 represents temporary transfer (Temporarily Moved)
Differences between the two
1) for users
There is no difference between 301 and 302, because the URL jump in the browser is changed to a new URL address.
2) for search engines
Website hijacking
What is the relationship between 302 redirection and URL hijacking? This should start from how the search engine handles 302. By definition, when A 302 redirection is made from website A to website B, the implicit meaning of host server is that website A may change its mind at any time, re-display its content or switch to another place. In most cases, when receiving a 302 redirection, most search engines generally only need to capture the target URL, that is, B.
In fact, if the search engine crawls the target website B for 302 of the requests, there is no need to worry about URL hijacking. The problem is that sometimes search engines, especially Google, cannot always capture target URLs. Why? For example, sometimes website A is very short, but it performs A 302 redirection to website B, while website B is A very long and messy URL, it may even contain parameters such as question marks. Naturally, website A is more user-friendly, while website B is both ugly and user-friendly. At this time, Google is likely to still display website.
Because the search engine ranking algorithm is only a program rather than a person, when encountering a 302 redirection, it cannot accurately determine which website is more appropriate like a person, this leads to the possibility of URL hijacking. That is to say, an immoral person makes A 302 redirection to your web site B on his own Web site A. For some reason, what Google search results show is still Web Site, however, the webpage content is the content on your website B, which is called URL hijacking. What you wrote so hard was stolen by others.
Configure 301 302 in Nginx
1) rewrite the URL address using the rewrite function of the server
Vim www. conf
Server {
Listen 80;
Server_name bkjia.com;
Location /{
# Rewrite ^/(. *) http://www.bkjia.net/#1 permanent; #301 permanent redirect
Rewrite ^/(. *) http://www.bkjia.net/#1 redirect; #302 temporary jump
}
}
Server {
Listen 80;
Server_name www.bkjia.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 and obtain the http status code.
[Root @ db02 ~] # Curl-I http://bkjia.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.bkjia.net/# Jump address
Website monitoring 302 Problems
We usually use scripts to monitor web servers. Status Codes 200, 301, and 302 indicate normal, but there are also special cases, such:
[Root @ db02 ~] # Curl-I-s-o/dev/null-w "% {http_code} \ n" http://bkjia.com
302 # bkjia.com does not exist (302 FOUND)
[Root @ db02 ~] # Curl-I-s-o/dev/null-w "% {http_code} \ n" http://muu.cc
302 # muu. cc exists (302 Moved)
Therefore, you can either monitor the web server port or delete 302
12345 # 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 is more worry-free.
This article permanently updates the link address: