Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

should I send status as 404 or 200?

I am using Rails to build a web application. In case a record is not found for a url say http://example.com/city/non_existant_city then I have following code.

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

In firefox I see the message.

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

This makes me wonder should I send status as 200. I was sending 404 so that web crawlers can understand that this link is consistently returning 404 so after a while give up on that link.

like image 422
Nick Vanderbilt Avatar asked Jan 23 '23 14:01

Nick Vanderbilt


2 Answers

You should use 404. Not only do crawlers stop visiting invalid links, but you are not penalized for duplicate content if it's a 404 page, as you would if it was a 200.

As for Chrome, it only replaces 404 pages if the contents are too short (less than ~520 chars)

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

like image 113
Johnco Avatar answered Feb 01 '23 00:02

Johnco


If you're telling the end user that the page doesn't exist, then send a 404.

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

A lot of browsers display "friendly" 404 pages, which is why you aren't seeing your message.

like image 29
Seth Avatar answered Feb 01 '23 01:02

Seth