• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer

REST API Tutorial

  • REST
  • JSON
  • Dark Mode
Home / HTTP Status / HTTP Status 301 (Moved Permanently)

HTTP Status 301 (Moved Permanently)

HTTP Status 301 is one of the redirection related statuses, which indicates that the resource requested has been permanently moved to the URL given by the Location header. And all the future requests should use the new URI.

Redirection is the process of forwarding the request from one URL to a different URL. The specification for Status 301 requires the request method (and the request body) not to be altered when the redirection is performed.

It is recommended to use the HTTP 301 only for GET or HEAD methods.

Why a URL needs to move permanently?

Generally, changing the URLs of resources is not advisable. Still, we can come across unavoidable situations where we must be making the changes to the URL of a resource.

A few such examples can be:

  • Moving the resource from HTTP to HTTPs protocol
  • Resource has been discountinued and alternate resource is available in new URL

Location Header

The server SHOULD generate a Location header field in the response containing the new location of the resource.

Client request

GET /index.php HTTP/1.1
Host: www.example.com

Server response

HTTP/1.1 301 Moved Permanently
Location: https://example.com/index.asp

Cachable

A 301 response is cacheable by default; i.e., unless otherwise indicated by the method definition or explicit cache controls.

Refer these cache header for more information.

Response Handling

  • If a client has link-editing capabilities, it should update all references to the requested URL with the new URL.
  • Search engines (Google and Bing) replace the old URL in the search results, and the old URL will eventually disappear. Link juice will pass from the old URL to the new URL.
  • The browsers will automatically detect the 301 response code after that it will read the new location URL and redirect the request to that new location.

Reference : RFC 7231

Was this article helpful?

TwitterFacebookLinkedInReddit
Previous Tutorial:
HTTP Status 204 (No Content)
Next Tutorial:

Reader Interactions

Comments

  1. Alexander Holbreich says

    November 18, 2020 at 6:55 pm

    The browsers will automatically detect the most of the 3xx code class which makes it not very suitable for API in cause your clients are java script based Rich clients. This response will not reach the JavaScript code.

    So at least you should only use it how it meant in HTTP. Clear redirection on GET or HEAD and no custom semantics.

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Search Tutorials

Learn REST

  • What is REST?
  • REST Constraints
  • REST Resource Naming Guide

Guides

  • Caching
  • Compression
  • Content Negotiation
  • HATEOAS
  • Idempotence
  • Security Essentials
  • Versioning
  • Statelessness in REST APIs

Tech – How To

  • REST API Design Tutorial
  • Create REST APIs with JAX-RS

FAQs

  • PUT vs POST
  • N+1 Problem
  • ‘q’ Parameter

Resources

  • What is an API?
  • Comparing SOAP vs REST APIs
  • HTTP Methods
  • Richardson Maturity Model
  • HTTP Response Codes
    • 200 (OK)
    • 201 (Created)
    • 202 (Accepted)
    • 204 (No Content)
    • 301 (Moved Permanently)

Footer

References

  • The dissertation by Roy Thomas Fielding
  • Uniform Resource Identifier (URI, URL, URN) [RFC 3986]
  • Internet MediaTypes
  • Web Application Description Language (WADL)

Meta Links

  • About
  • Contact Us
  • Privacy Policy

Blogs

  • How To Do In Java

Copyright © 2020 · restfulapi.net · All Rights Reserved. | Sitemap