views:

74

answers:

5

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?

+1  A: 

That depends, I suppose.

If photo.php?id=123 is a page showing the photo with an id of 123, then yes, it should throw a 404. 404 means that a resource was not find when it was expected to be found - this is semantically correct.

However, on the odd chance that your semantic intent for photo.php?id=123 was for it to be a page searching for a photo with the id of 123, then it's perfectly correct to return 200 with a message saying that no results were returned.

Ultimately, it doesn't make a huge amount of difference. I'm not very well acquainted with how HTTP response codes affect the way search engines index your page, but I suspect that 404's will not get indexed in the same way. You probably don't want the page being indexed if there's nothing to display.

TL;DR I would throw 404.

Jamie Wong
"Ultimately, it doesn't make a huge amount of difference." It does for search engines. I'm not an expert and I don't know to which extend, but if you always return a 200 with the same content, you have multiple pages pointing to the same content. I think this is bad..
Mike Gleason jr Couturier
A: 

Yes, you should throw a 404 if it has never existed:

The server has not found anything matching the Request-URI. No indication is given of whether the condition is temporary or permanent.

But if it has existed before, you should respond a 410:

The requested resource is no longer available at the server and no forwarding address is know

From Status Code Definitions

Thierry-Dimitri Roy
That link confirms that 404 does in fact apply to the entire URI, including query string.I was scared that a 404 on photo.php?id=123 would scare browsers from loading photo.php?id=334, but it seems that is not the case.
Full Decent
A: 

Hi,

I think you should throw the 404. This you can easily make using a .htaccess file,

Hope that helps,

Ramon Araujo
+3  A: 
Crozin
+3  A: 

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."

josh3736