Search code examples
http-status-code-404http-status-codes

Is HTTP 404 appropriate for out of range page number on paged content?


I have a site that is mainly showing a paged list of content (articles, data element's, etc.), and I'm wondering about returning HTTP 404 when user navigates outside of the available list range (eg. by hand edited url).

Some sites just display "No results/Page number out of range" and some return additionally return HTTP 404 status.

What's your take on that, and why?

UPDATE

It's not and api response. This question is in regard to user viewed pages that among other things show a list/table in the main area.

UPDATE

Borderline example: 1'st page is a page out-of-range because no data for the shown list exists yet.

Should I show 404? If it where search result's I wouldn't mind... but for plain viewing of paged list/data table seems harsh.

Example: the first day of Stack Overflow run and no questions exist yet, you hit the home page and what, 404 or just a 200 with "No questions yet" message?


Solution

  • I would go for 404 when page number is != 1, regardless where the page number is placed in the URI (query string or in the path), and go for the soft 404 when there's no results but page number is exactly 1 or not given.

    Why?

    Result set page 1 is exists as a landing page for the results set (even search results -- see Google here), so it's found and exists (if not for showing result set) to tell you that there is no data in the result set.

    Then any result set page number outside result set's range is not found, there's no meaningful point for these page/resources to exist, hence 404. If one should argue that they exist to convey a message "No MORE data", hence they are meaningful, hence need to be indexed - search engine nightmare!

    HTTP 400 Bad Request is bad choice because it would suggest that request can never be correct.

    HTTP 400 Bad Request - request could not be understood by the server due to malformed syntax. The client SHOULD NOT repeat the request without modifications

    404 Not Found is vague about this case, and in this case can be IMO interpreted both ways

    The server has not found anything matching the Request-URI. No indication is given of whether the condition is temporary or permanent. The 410 (Gone) status code SHOULD be used if the server knows, through some internally configurable mechanism, that an old resource is permanently unavailable and has no forwarding address. This status code is commonly used when the server does not wish to reveal exactly why the request has been refused, or when no other response is applicable.