Mobile app version of vmapp.org
Login or Join
Barnes591

: How do I know whether a URL returns an HTTP 404 status code? 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,

@Barnes591

Posted in: #Http #Url

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:

Thanks for pointing out!

10.04% popularity Vote Up Vote Down


Login to follow query

More posts by @Barnes591

4 Comments

Sorted by latest first Latest Oldest Best

 

@Dunderdale272

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



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.

10% popularity Vote Up Vote Down


 

@Alves908

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
}

10% popularity Vote Up Vote Down


 

@Sherry384

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

10% popularity Vote Up Vote Down


 

@Bryan171

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

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme