As far as HTTP is concerned, there is no such thing as a directory or a file, only a "resource" identified by a URL.
In HTTP, a client sends a request to a server for a specific URL; that server can perform whatever processing it likes in order to respond to that request, and respond with either an error code, or a string of content. The type of content returned is identified by the server with a header such as Content-Type: text/html, and the client doesn't need to guess it based on the URL.
The simplest way for a server to respond to a URL is to map it to a directory structure on the local file system, and return the content of the file it finds there. When a URL would map to a directory, the server would often be configured to return the contents of a particular file in that directory, such as index.html. The server would also need to decide what Content-Type to label each file as, for instance based on the file name's "extension".
If you had such a server, you could easily create directories named "foo.html". If you created an HTML file named "foo", you would need to tell the server somehow to serve it with an HTML Content-Type, and then it would work fine.
But it's important to understand that that is entirely a convention used by that particular server, and not something the client can assume. Another server could map all URLs directly into database queries, with no underlying filesystem at all, so the notion of "directory" would have no meaning.