Get the filetype of a webpage

82 Views Asked by At

Is it possible to get the filetype of a webpage. I see sometimes webpages like:

random.com/game

What is the filetype of game?

I can of course try to guess the filetypes, such as game.html, game.php etc. but is there a way to get it?

2

There are 2 best solutions below

0
On BEST ANSWER

No, it's not possible. There are several reasons for this:

  1. /game could be a sub-directory. In this case, the file could be one of any default index pages for the web server serving the page.

  2. /game could be configured via server routing to point somewhere completely different on the site.

  3. /game could be a route in a web application. In this case, there's no single file for the page. The server could route the request to application code which uses any number of files to construct the page.

2
On

You can read what the server is serving the contents as (MIME type) by viewing HTTP headers, but the actual filetype cannot be determined with accuracy from a remote host via HTTP/HTTPS.

For example, here is the response for a successful web page request:

HTTP/1.1 200 OK
Date: Mon, 08 Dec 2014 21:50:36 GMT
Server: Apache/2.2.27 (FreeBSD) PHP/5.5.11 mod_ssl/2.2.27 OpenSSL/0.9.8y DAV/2
Content-Length: 311
Connection: close
Content-Type: text/html; charset=iso-8859-1

So the server is telling you that the page is text/html ... but it could've been generated by any number of server-side technologies (PHP, Java, Python, and more) instead.