Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If record is not found in the database, should I return a 404?

Tags:

seo

I have pages with structure like this some_page?id=123

Sometimes records are deleted, but those pages still get visited by people and search engines. One problem is that I have a php script and no MVC structure, so I have to query the DB all on the same page before I find out that the user record does not exist.

Should I return a 404 in that case? Or what is best practice?

Thanks!

like image 775
GeekedOut Avatar asked Dec 05 '22 18:12

GeekedOut


2 Answers

If the client (users, search engines, etc.) requests a resource that does not exist and has never existed, a 404 status ("Not Found") should be returned.

However, if a resource is requested that once existed and has since been permanently removed, a 410 status ("Gone") should be returned. A 410 status specifically states that the resource will never be available in the future, and triggers search engines to remove that page from their indexes.

A 301 status is used if a resource's location has changed permanently.

like image 196
VettelS Avatar answered Feb 24 '23 15:02

VettelS


A 404 is when something is not found and since the resource being looked up is not found, it seems entirely appropriate to me.

like image 41
AHungerArtist Avatar answered Feb 24 '23 14:02

AHungerArtist