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

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

Sometimes posts are deleted, but people and search engines still visit these pages. One of the problems is that I have a php script structure and not MVC, so I have to query all the databases on one page before I find out that the user record does not exist.

Should I return 404 in this case? Or what is best?

Thanks!

+4
source share
5 answers

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

However, if the requested resource once existed and has since been deleted, the status 410 ("Gone") has been returned. Status 410 indicates that the resource will never be available in the future and launches search engines to remove this page from its indexes.

State 301 is used if the location of the resource is constantly changing.

+10
source

A 404 is when something is not found, and since the resource viewed is not found, it seems to me quite suitable.

+5
source

It depends on whether you want to keep the user on your site. If you redirect forever to another page, make sure that you also have 301 in the headlines so that search engines do not punish you for many links pointing to the same page.

A 404 is fine, but you will get bounces from this page if users' browsers do not display any content.

I personally believe that the best approach is to show a user-friendly page for users and to correctly set the headings for search engines.

http://en.wikipedia.org/wiki/List_of_HTTP_status_codes

+1
source

Yes. this would be correct if you did not have a replacement to use. it would be better if you used a server with a similar resource or even redirected it.

0
source

Yes - but do not forget to offer the visitor additional related content. Just because the URL was not found does not mean that the visitor should be ignored. Display a 404 user page with some other sections of the site that may be taking place - perhaps the most visited pages, ...

0
source

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


All Articles