Which status code should invalid parameters return? First distinguish invalid formats from missing data

ProcrustesPR

The status code for an invalid parameter depends first on which of two situations applies: the format is valid but no matching data exists, or the format itself is invalid. In the discussion, one respondent argues that a page reporting missing content should return 404, rather than display an error message while returning 200. When an integer-only parameter receives text, that respondent recommends 400, while another commenter considers 404 acceptable. The discussion offers no consensus on this second case.

ProcrustesPRProcrustesPRHow should I divide my DIY SEO budget?

First identify what makes the parameter “invalid”

Two URLs with an id parameter can present different problems:

  • The format meets the requirements, but no data is found: For example, in index.php?id=4, the parameter is an integer, but the application cannot find matching content.
  • The format does not meet the requirements: For example, in index.php?id=toto, the id field accepts only integers but receives text.

The first case concerns missing content; the second concerns a parameter that fails validation. Making this distinction is more precise than “return 404 whenever something goes wrong on a page.” Even if both cases display an error page, they do not necessarily require the same status code.

Displaying a not-found page does not mean the response is 404

The first respondent warns that a dynamic website may display a “404” message when no data is found while its actual HTTP response remains 200 OK. In that respondent’s view, a genuine 404 page should return the 404 Not Found status code.

When checking such pages, look beyond the on-screen heading and explanation to the actual response status code. For example, if id=4 has no matching data, even a clear message that the content does not exist does not mean the status code has been set correctly.

No consensus on text supplied to an integer field

For id=toto, the first respondent considers the request invalid and recommends 400 Bad Request rather than 404. Another commenter argues that 400 usually indicates an HTTP protocol-level problem, such as a malformed header. That commenter therefore advises against using 400 for invalid parameter values and considers 404 acceptable.

The latter commenter also paraphrases other answers, mentioning 422 or 403 as possibilities when the syntax is correct but the parameters are invalid. However, the supplied discussion does not include the full reasoning behind those answers, so it does not establish either code as a general-purpose solution.

Before choosing a status code, clarify why the parameter is invalid and how the page handles that situation. As for whether an invalid format calls for 400 or 404, the discussion remains divided; neither position can be treated as an accepted rule.

ProcrustesPRProcrustesPRWhy can I not find my published article on Google?

Status codes for invalid parameters: perspectives from across the web

How can dynamic websites set status codes for error responses?

Respondents in the discussion mention setting response status codes with PHP’s header function or .NET’s HttpWebResponse.StatusCode property. Choosing which code to return still depends on why the parameter is invalid. The discussion does not provide complete code or specify which versions these approaches apply to.

ProcrustesPREight SEO essentials for beginners: Website speed

References

  1. 404 page needs meta description (just to make Google happier)?webmasters.stackexchange.com — Discusses: How can dynamic websites set status codes for error responses?
  2. 404 page needs meta description (just to make Google happier)?webmasters.stackexchange.com — Source used in the article above.

Related articles

How should I divide my DIY SEO budget?Why can I not find my published article on Google?Eight SEO essentials for beginners: Website speedEight SEO essentials for beginners: Getting your pages indexedEight SEO essentials for beginners: Page titles and descriptionsThe Five Most Common Mistakes SEO Beginners MakeHow to Set Up Heading Tags for SEO: Define Topics and Hierarchy Before Adding KeywordsWhat are the benefits and development challenges of SPAs?
ProcrustesPR
ProcrustesPR