Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

For any given URL, how can I (dis)confirm whether it returns an HTTP 404 status code?

I found this tool but isn't there a cleaner, more natural way to find out, independently of other people's tools?

For example, how do I know whether this broken link is a genuine 404 or not? I took a quick look at the source code but I saw nothing about a 404 status code.

Edit

I found what I was looking for in developer tools/Google Chrome Console. The broken links turns out to be a 404 indeed:enter image description here

Thanks for pointing out!

share|improve this question

4 Answers 4

up vote 3 down vote accepted

HTTP status codes are sent on the HTTP level (e.g., when requesting resources), so you can’t find them in the HTML. The server decides which status to send when you request a page, so the very same page could send 404 and ten seconds later 200.

Various tools can be used to display the received HTTP status codes.

You could use

  • your browser, which most likely ships with developer tools (like Firefox: Ctrl + Shift + q )

  • command line tools (like cURL: curl -I http://en.wikipedia.org/)

  • web apps (like the one you mentioned)

  • … (If you are looking for a specific tool that matches your requirements, you could create a question on Software Recommendations)

Note that it’s possible (i.e., if the server is configured in such a way) that different clients (based on user-agent, language settings, IP address etc.) get different results.

share|improve this answer

If you have firebug you can see the difference, they actually return the 404 header.
A website is perfectly capable of returning content with a 404-header:

header("HTTP/1.0 404 Not Found");
echo file_get_contents('page-not-found.html');

So: How to check for the statuscode:
See answer 1 for a cURL solution, answer 2 for a get_headers() solution, or use your console's resources tab to check for them manually

share|improve this answer

As noted above, you could check with cURL if you're interested in building your own 404 checker. An example with PHP:

$resourceUrl = 'http://example.com/test.html';

$ch = curl_init($resourceUrl);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_exec($ch);
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

if($statusCode == '404'){
    //resource does not exist
}
share|improve this answer

If you're using Firebug with Page Speed (generally helpful for web developers) then you can look in the Resources tab.

Firebug with Page Speed

This will show you the HTTP header returned for every resource on a page, including the page itself. This also helps identify redirects on the way to a 404 page if things on your site aren't coded/configured properly.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.