David Metcalfe David Metcalfe - 1 month ago 14
HTTP Question

Why does a directory exist and not exist on a web server simultaneously?

While I'm sure the title could be improved for clarity, my meaning is thus:

When fetching a URL for a file download at

http://example.com/dir1/dir2/file.zip
, the response code is
200
, yet attempting to access
http://example.com/dir1
, or
http://example.com/dir1/dir2
, elicits a
404
response code.

Why is this?

Answer Source

URLs don't necessarily correspond to actual directories on the server. Ultimately the path component of a URL is just a name; the server can translate that name to whatever it wants on the back end.

In this case it seems likely that /dir1/dir2/ is a directory on the server, but even so that doesn't mean anything. The server knows about a resource named /dir1/dir2/file.zip, but doesn't know anything about a resource named /dir1.