Search code examples
htmlwebdirectoryhyperlinksubdirectory

Following a ../ link on my live site behaves differently then when developing it with vscode and Chrome


While debugging my site, I have noticed a weird thing happening. Lets say the html file has a hyperlink like so:

<a href="../">This hyperlink uses "../" to take you back one directory</a>

If I debug my own site in vscode and use chrome, if I click this, it gives me a weird page that says "Index of /Users/myusername/code/public_html/aboutme/" and shows all of the files in that directory. But then when I upload the files to my host, everything works just fine. Why is this? I suspect it may have to do with the way that "index.html" works.


Solution

  • A typical configuration for an HTTP server which is serving static files (i.e. mapping URLs directly onto files on the filesystem) is that if the URL maps onto a directory then to look for a file named index.html (or similar) and response with that.

    For example, when using Apache HTTPD, this is handled by the DirectoryIndex directive.

    When dealing with a file:/// scheme URL then there is no HTTP server which can do that mapping and the code internal to browsers which handles file:/// scheme URLs doesn't do it either.