1

I have the following routes set up:

/business //look for a business
/business/biz/:id //look at a specific business

What I did is that if someone goes to /business/biz it redirects to /business. My question is what status code I should use for that? I don't think it's 301 or 302 because it's not a permanent move, and it's also not temporary, it's just a page that doesn't exist with a consistent redirect to a specific page.

//get /business/biz page
router.get("/biz", (req, res) => {
  res.redirect("/business");
});

I looked at different questions here on Stack Overflow but didn't find a case that matches mine.

IQbrod
  • 1,590
  • 1
  • 2
  • 20
Mendi Sterenfeld
  • 334
  • 3
  • 18

2 Answers2

1

To redirect /business/biz on /business you should return a 308 Permanent Redirect.
This is a quote from Wikipedia about status 308 :

The request and all future requests should be repeated using another URI. 307 and 308 parallel the behaviors of 302 and 301, but do not allow the HTTP method to change. So, for example, submitting a form to a permanently redirected resource may continue smoothly

You should also check this answer explaining differences between 301, 308, 302, 307 and is well written.

IQbrod
  • 1,590
  • 1
  • 2
  • 20
0

It is recommended to use the 301 code only as a response for GET or HEAD methods and to use the 308 Permanent Redirect for POST methods instead.

Check the full article here