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
?
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."
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With