Redirect Redirect knowledge of

Today after work to see some of the basics redirect, it opened the eyes are also considered. Previously often use 301 and 302, but never used 3XX and find out about other status codes, also found a lot of knowledge and solve problems related to the original inside.

Redirect process

A first browser to access the server's URL, server A returns to location B with a status code and the URL header 3XX, the browser reads 3XX response status code, the acquired location of the head, and then jumps to the server B the URL.
Need to know, jump the browser is launched. If the server to a non-browser terminal returns a status code 3XX, it might be unable to complete the redirection.
In particular, there should have been run for a long time, PHP write API interface. Have been using HTTP, often hijacked, then the leadership want to make into an encrypted HTTPS, but the client can not send edition. Later, the server will consider the whole slave interfaces HTTP 302 to HTTPS, to discuss the feasibility of this program. If you know the above processes and knowledge that flew on the PASS program.

Permanent redirect

Resources represent a permanent jump to a new URL.
A more common case is the old station to migrate to the new station, the old station directly off the old station page has been indexed by search engines, this time using a permanent redirect scheme.
Two permanent redirection state code
301, typically a redirection request using the GET method, is used regardless of what the requesting method.
308, 301. The redirected to the original request method must be used to complement and inclusions access.

Temporary Redirect

Means that the resource is only a temporary jump to a new URL
temporarily redirect a total of five state code, used also corresponding to two 302 and 307. The
302 redirect requests typically use the GET method, no matter what the original request using methods.
303, does not mean that resource changes, but said instead of the original request in response to the new URL. No matter what the original request using the method. Consistent with the 302, so the market rarely use 303, are using 302.
307. 302. To supplement use and must redirect the original request to access the package body.
Baidu is the use of 307 jumps, the browser will enter http://www.baidu.com 307 to https://www.baidu.com

300, the request may be a variety of responses, the browser may select one of them is. There is no standard server can be followed to replace the user to make a selection.
304, tells the browser, the requested content has not changed since the last visit. The resources can be obtained directly from the browser cache.
The latter two are not commonly used.

Use is more 301302307308

Redirection loop problem

ERR_TOO_MANY_REDIRECTS
this error very common. If you access the page then redirects A visit B, then B letting redirect access to A, this is a redirect loop. Multiple redirects will report the mistake.

Production environment met once, and once found an error ERR_TOO_MANY_REDIRECTS on the log, but did not find 3XX jump code on Nginx configuration ah, how the cycle jump. Later I saw this configuration

    location / {
        try_files $uri $uri/ /index.html$is_args$args;
    }

Later found no index.html in the root directory, uri does not exist, then uri / directory does not exist, and finally launched an internal sub-request to index.html.index.html does not exist, and the location, repeatedly redirected. The last error ERR_TOO_MANY_REDIRECTS.

Guess you like

Origin www.cnblogs.com/feixiangmanon/p/11105239.html