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

1 - 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.

3 - Example

3.1 - Javascript

In javascript, you can redirect with the window.location.assign function


3.2 - Permanent Redirect with htaccess

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

4 - List

4.1 - 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.

4.2 - 301 - Moved Permanently

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

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

4.3 - 302 - Found

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

Therefore, HTTP/1.1

  • added the status codes 303 and 307 to distinguish between the two behaviors. 302 is then superseded by 303 and 307 in HTTP/1.1 but preserved for backward compatibility.

4.4 - 303 - See Other URI

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.

4.5 - 304 - Not Modified

When the client (browser generally) is serving the request from its local cache, it responds with a 304 status to show an implicit redirection to the cached resource.

rfc7232 - Hypertext Transfer Protocol (HTTP/1.1): Conditional Requests - section-4.1

4.6 - 307 - Temporary redirect

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

4.7 - 308 - Permanent redirect

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

5 - Documentation / Reference

Data Science
Data Analysis
Data Science
Linear Algebra Mathematics

Powered by ComboStrap