API Fundamentals Course
API Fundamentals
/
Intermediate

3xx Redirection Codes

Definition

HTTP status codes ranging from 300-399. They indicate that further action needs to be taken by the user agent (browser) in order to fulfill the request, usually by navigating to a different URL.

Explain Like I'm New

The server saying: 'The thing you are looking for isn't here anymore, but I know where it is. Go look over there instead.'

Real World Example

You try to visit `http://google.com`. The server returns a `301` redirecting you to `https://google.com` (forcing encryption). You try to access a private dashboard without logging in. The server returns a `302` redirecting you to the `/login` page.

Common Use Cases

  • •SEO preservation
  • •Authentication routing
  • •Domain migrations

Interactive Example

Loading...
Console output will appear here...

Interview Questions

basic

  • What is the difference between a `301` and a `302` redirect?

intermediate

  • What is a `304 Not Modified` code, and how does it save massive amounts of bandwidth?

Flash Cards

Question

301 vs 302?

Click to reveal answer
Answer

`301 Moved Permanently` tells Google to update their search engine results because the old URL is dead forever. `302 Found (Temporary)` means 'go to this other URL just for right now', and Google will not update their search index.

Question

304 Not Modified?

Click to reveal answer
Answer

It is a caching miracle. The browser asks the server: 'Give me the logo image, but I already have a copy from Tuesday.' The server checks the DB, sees the logo hasn't changed since Tuesday, and returns `304 Not Modified` with NO image attached. The browser immediately uses its cached copy, saving megabytes of data.