Skip to content
EuroVPSEuroVPS

Ultimate Guide to Understanding HTTP Status Codes: 300 Series

HTTP 300 status codes are reserved for redirects. Most redirects will be transparent to the end-user and are handled entirely by a user-agent.

By Thomas

Updated 6 min read
69 http errors guide 300 hero

To better understand why redirects are so important it may be helpful to understand why a redirect would be used in the first place.

Redirects usually result from a change. This can be a change of computing resources, change in marketing terminology, change in policy, change in SEO strategy, or change in business operations. Somewhere, something has changed and requires the same URI to be accessible across a different location.

When changes are made search engines and other resources will possess the older links until a site is re-indexed.

The alternative to a redirect would be a 404 "document not found" error.

An extreme scenario forcing the need to redirect a user-agent would be a company reorganizing its product line. Let's say, for example, ACME Co. moved the Widgets line to ACME Labs. Current ACME policy dictates web structure is of: acmeco/{division}/{productline}.

So ACME might have:

www.acme.com
www.acme.com/marketing/seotechnologies/
www.acme.com/marketing/billboards/
www.acme.com/consumergoods/sports/
www.acme.com/consumergoods/clothing/
www.acme.com/consumergoods/widgets/
www.acme.com/labs/widgets/
www.acme.com/labs/foobars/
www.acme.com/labs/betaproducts/

ACME Widgets has been located at www.acme.com/consumergoods/widgets/  for the past 5 years and gets tens-of-thousands of hits per hour at that location.

Can you imagine how much revenue this simple move could cost ACME Co. in lost sales, customer service responding to complaints, as well as executives answering the phone for official press statements about the beloved Widget line?

What about search engines? A good portion of ACME Co. Widget sales is from search engine hits. Not to mention the Google Ads campaign and URL on brochures and business cards.

A 300 series redirect can solve the problem for everyone at ACME Co. ACME can simply configure the web-server to redirect all requests asking for www.acme.com/consumergoods/widgets/ to www.acme.com/labs/widgets/.


Real World Example of a 301 Redirect

At EuroVPS we use a 301 redirect to make sure visitors use the secure HTTPS protocol.

Here is exactly how the 301 Redirect assures every visitor will access HTTPS when visiting EuroVPS:

  1. user-agent requests http://www.eurovps.com/
  2. web-server replies with a 301 status code
  3. the web-server sets a Location header to the https version
  4. most user-agents will automatically redirect to the new URL
Redirect when Location Header is not followed
a message is displayed for user-agents that do not honor the location header.

Redirects can be accomplished in scripting languages such as Python Django, PHP, and ASP .Net. However, a more robust solution is to leave redirects up to the web-server with a re-write rule.

Redirect in PHP:

  <?php // Permanent 301 Redirect via PHP
  	header("HTTP/1.1 301 Moved Permanently");
  	header("Location: https://eurovps.com/");
  	exit; // stop the script once the redirect is sent

The problem with doing redirects at this high layer is that we could end up editing 100 pages! Or even worse, hacking up code in a content management system that may not do redirects as we would like.

A much more elegant solution is to have the web server do all the redirecting for us.

In Apache redirects could be done as follows:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

In nginx the same redirect is one line in the server block that listens on port 80:

server {
    listen 80;
    server_name www.example.com;
    return 301 https://$host$request_uri;
}

Status Code 300 Redirects

300 Multiple Choices

300 Multiple Choices is a redirect that is rarely used in the real world. 300 Multiple Choices is encountered when a requested resource points to multiple destinations for the same requested document. A choice of action is presented to the end-user allowing them to select the choice desired.

301 Moved Permanently

301 Redirects are common because search engines treat a 301 as a permanent move: they update their index to the new URI and carry ranking signals over.

When a client encounters a 301, bookmarks and automated user-agents should be updated to the new URI.

302 Found

302 redirects should be used when a requested URI is temporarily at a new location. The user-agent follows the Location header to the temporary URI. For historical reasons most clients turn a POST into a GET when they follow a 302; use a 307 when the method must be kept.

Unlike with a 301, user-agents should keep using the original URI, because this is a temporary redirect.

303 See Other

303 is mainly for POST and PUT requests that are taken to a different URI than originally requested by the user-agent in its POST or PUT request.

An example could be when uploading a larger file that may take a few minutes:

  1. user-agent submits a large file using PUT or POST
  2. the file is destined to the original URI
  3. web-server returns a 303 redirecting to an upload status page
  4. user-agent will use GET via 303, requesting an upload status page

304 Not Modified

The 304 Not Modified is used for caching purposes. 304 is sent as a status to a user-agent requesting a check on current status of a cached page.

If the page requested is still current, the server answers with a 304 and no body, and the user-agent shows its cached copy to the end-user.

304 Redirect
Above is a check on a cached javascript file.

305 Use Proxy (deprecated)

305 Use Proxy is deprecated. The current HTTP specification, RFC 9110, lists it as no longer used, and browsers do not act on it. Do not use it.

307 Temporary Redirect

The 307 is similar to the 302 but requires the same request method be used on the redirected URI. This would be used, for example, when a POST request needs to be sent to another URI.

With a 302, most clients switch to a GET request to obtain the redirected URI.

308 Permanent Redirect

308 is the permanent counterpart of 307. Like a 301, it tells clients the resource has moved for good; like a 307, it requires the client to repeat the request with the same method. Use it when a permanent move must keep a POST as a POST.

The status codes in this guide are defined in RFC 9110 (HTTP Semantics).

From the EuroVPS blog archive, first published 12 December 2019.

All field notes