Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which Http redirects status code to use?

Tags:

rest

http

  • friendfeed.com uses 302.
  • bit.ly uses 301.

I had decided to use 303.

Do they behave differently in terms of support by browsers ?

like image 344
Jacques René Mesrine Avatar asked Dec 30 '22 11:12

Jacques René Mesrine


2 Answers

It depends on your purpose.

301 says “this isn't the proper URL, look elsewhere and use remember that other URL is better; don't come back here!”.

302 says “this is the proper URL which you should carry on using, but to actually get the content look elsewhere”.

303 is like 302 but specifically for redirections after a form submission.

If your purpose is a URL shortener then 303 isn't really relevant. It'll still work, but offers nothing over the normal 302. For a URL shortener I'd say 301 would be most suitable, as the other URL is the ‘real’ one. Saying 302 is trying to keep the ownership of the address and any SEO momentum caused by its use for yourself: a bit rude, but maybe you want to be rude.

like image 56
bobince Avatar answered Jan 02 '23 23:01

bobince


Different status codes have different meanings. The HTTP specification describes them: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html

301 — moved permanently (and change an

302 — found here

303 — find your response here, but use GET even if you started out with POST

If we take, for example, an Atom feed that has the URL changed for some reason (perhaps it is being moved to Amazon S3 or something). Given a 301 result, the feed reader should note that the feed has moved and update it's subscription. Given a 302, it will get the feed from its new location, but hit the original server looking for the original URI every time it checks for an update. (And a 303 would be silly in this situation).

like image 28
Quentin Avatar answered Jan 02 '23 23:01

Quentin