Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I throw a 404 to a request like /photo.php?id=123 if photo #123 does not exist?

The script will be called from a URL like example.com/photo.php?id=123 or example.com/photos/123 depending on if the have the pretty URLs featured enabled.

If photo #123 does not exist, a request to example.com/photos/123 should throw a 404 error. But, what about example.com/photo.php?id=123?

like image 707
William Entriken Avatar asked Aug 27 '10 17:08

William Entriken


2 Answers

The relevant RFC is 2616, specifically the sections on status codes, requests, and URIs. Specifically, the query string is considered part of the URI, so a 404 is the proper response since it means:

The server has not found anything matching the Request-URI.

If you can know that a photo has been permanently deleted, you may return 410.

I would not return 200 and say "no results found."

like image 184
josh3736 Avatar answered Oct 07 '22 01:10

josh3736


You should treat both ...?id=123 and .../123 URLs the same, cause they are equal - they just have a little bit different form.

And yes, you should throw an 404 - Not Found error cause given resource doesn't exists. However 404 pages shouldn't never look like:

404 Not found - you're @#$@#$@!

404 for URL like ...photo.php should contain a list of suggested resources (different photos that user might wanted to visit), some kind of search form - in other words: it should be a page that allows me to do something rather that just throw error message.

like image 38
Crozin Avatar answered Oct 06 '22 23:10

Crozin