HTTP - Redirect (status codes 3xx) - Client must take additional action

About

The HTTP 3xx class of status code indicates that the client (user or user agent) must take additional action to complete the request.

The redirect url is defined by the location header.

A user agent may automatically redirect a request.

An HTTP status code redirect means that the original resource has moved or is in another place, not that the browser should navigate to another URL.

The browser will then perform the same request but against another URI.

If the request has:

  • a GET method, an HTTP redirect will have the same behavior as a navigation
  • but for any other method such as a HTTP Post, the browser will perform the original request against the new URI. In this case, if you want the browser to navigate to another page after a HTTP Post, you should perform it with Javascript with the window.location.assign function
window.location.assign('https://example.com/path/to/navigation/page');

Example

Permanent Redirect with htaccess

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ https://gerardnico.com/$1 [R=301,L]
</IfModule>

List

300 - Multiple Choices

The client is shown with a multiple choice.

For example, the client must choose between:

  • multiple video format options,
  • different files with different extensions,
  • different word sense disambiguation.

301 - Moved Permanently

This and all future requests should be directed to the given URI.

For Googlebot, 301 means that:

  • there is a better version than a given URL.
  • this duplicate page is deprecated

You would choose this redirect when you change your domain name for instance.

For A/B test, use 302 redirects, not 301 redirects

If you’re running an A/B test that redirects users from the original URL to a variation URL, use a 302 (temporary) redirect, not a 301 (permanent) redirect.

This tells search engines that this redirect is temporary—it will only be in place as long as you’re running the experiment—and that they should keep the original URL in their index rather than replacing it with the target of the redirect (the test page). JavaScript-based redirects are also fine.

302 - Found

After a post, the response may be a 302, to indicate that:

  • the post was successful redirect
  • the next step is to show another page

With HTTP/1.0 specification, the client must perform a temporary redirect (the original describing phrase was “Moved Temporarily”), but popular browsers implemented 302 with the functionality of a 303

The browser have implemented the 303 behavior for a 302 (ie when receiving a a 302 response from POST requests will send a GET request to the Location response header)

Therefore, HTTP/1.1, added the status codes 303 and section307 to distinguish between the two behaviors. 302 is then superseded by:

  • 303
  • and 307

in HTTP/1.1 but preserved for backward compatibility.

303 - See Other URI

example of usage: used to redirect for tracking analysis For instance, after the user click on a tracking link (in an email or in on page)

A 303 response to a GET request indicates that the origin server does not have a representation of the target resource that can be transferred by the server over HTTP.

However, the Location field value refers to a resource that is descriptive of the target resource, such that making a retrieval request on that other resource might result in a representation that is useful to recipients (user generally) without implying that it represents the original target resource.

By sending a 303 when asked for a non-information resource and redirecting to an information resource about the non-information resource, the server answers the requesters information need without having to supply the actual thing 1)

Since HTTP/1.1, a 303 will always end by a GET request to the new URL from the client.

When a 303 is received in response to :

  • a GET method, the response to the request can be found under another URI
  • a POST (or PUT/DELETE), the client should presume that the server has received the data and should issue a redirect with a separate GET message.

2)

304 - Not Modified

A 304 is send by the server when it receive a conditional get request from the client because it has already a response in its cache.

More see 304 - Not Modified HTTP Status

Http Status 304 Chrome Devtool

307 - Temporary redirect

provides a new URL for the browser to resubmit a GET or POST request.

The requested URL has been moved to a temporary location and will be back if not, uses a section302.

Used in case of A/B test for instance.

308 - Permanent redirect

provides a new URL for the browser to resubmit a GET or POST request.

Documentation / Reference





Discover More
Chrome Devtool Network 304
304 - Not Modified HTTP Status

The 304 Not Modified indicates to the browser that the resource was not changed and that it can serve it from its cache
HTTP - Location Header

location is a response http header that contains the URL value of a redirect.
HTTP - Status Code

The status code is the exit code of request returned to the client via the first line of a response. For example: a file not found error is a 404 code, a server error is equivalent to a 5xx code....
HTTP Refresh Header

The refresh HTTP header
How does Single Sign-on (SSO) authentication work?

Single Sign-On (SSO, trusted sign-on) is a federation identity application. It's the ability: to require a user to sign once and gain access to different applications. SSO is also known as: as...
Chrome Devtool Network 304
How to implement and check a Web / HTTP cache ?

Implementing and verifying that the HTTP cache is set and working properly is not a straightforward task. This article gives you a step by step.
Map Of Internet 1973
Network - netcat (nc, ncat)

netcat is a net client/server command line tool for TCP or UDP protocol. It can: reads and writes data across network connections acts as a client but also as a server You can see it as the equivalent...
Oauth
Oauth - Flow (Abstract Protocol Flow)

The abstract OAuth 2.0 flow describes the interaction between the four roles. For each type of grant, you got a flow: Type / Flow Description Client Type (Public / Private) Direction Type Redirection...
Card Puncher Data Processing
Statistics - A/B (Test|Testing)

A/B Null Hypothesis test set up multiple copies of the website, redirect users randomly to each copies via 307 status measure which design improves the target the most. Gather Samples Assign...
Netstat Tcp Listening Socket
TCP - Connection

This article is a connection within the TCP protocol. A TCP server may serve several clients concurrently with the same local socket address (ie local IP address and port number) by creating a child...



Share this page:
Follow us:
Task Runner