Should I send 404 or 200 status?

I use Rails to build a web application. In case the entry was not found for the URL, say http://example.com/city/non_existant_city , then I have the following code.

render :text => "record was not found", :status => :not_found 

In firefox, I see a message.

In chrome (on mac), I see a 404 chrome page, and this page does not display the message I'm sending.

This makes me wonder if I should send the status of 200. I sent 404 so that search bots can understand that this link constantly returns 404, so after some time, refuse this link.

+4
source share
3 answers

You should use 404. Not only do crawlers stop visiting invalid links, but you are not punished for duplicate content if this is page 404, as if it were 200.

As for Chrome, it only replaces 404 pages if the content is too short (less than ~ 520 characters)

See: http://perso.hirlimann.net/~ludo/blog/archives/2008/09/chrome-and-404s.html

+7
source

If you tell the end user that the page does not exist, send 404.

If you tell the end user that the page exists, but the record they were looking for does not create, then create a regular page (200) and display an error message in it.

Many browsers display "friendly" 404 pages, so you don’t see your message.

+1
source

Is it generally known that the record was not found? For example, people enter the name of the city, and then if the name is not found, can you give them alternatives? If so, then I would return 200 pages containing a new request box, etc.

If this is a web service, then 404 is fine, if all you want your api to return in such cases is "not found". But if you want your api to additionally return other information, then 200 (plus an error code without success and other information) is the way to go.

+1
source

Source: https://habr.com/ru/post/1300825/


All Articles