Page 1 of 1

./ = index.html

Posted: Tue Apr 22, 2014 3:45 am
by roedygr
HTMLValidator asked me to read

It asked me to replace all links of the form ../../../index.html with ./

To my astonishment, this trick works both on the web and locally.

The puzzle is, how does the browser know in which directory to look for the index.html?
Is it always the one directory off the root. Does it search the chain of directories back looking for an index.html?
Is this supposed to work if you have embedded index.html files in the tree to discourage directory listing?

Re: ./ = index.html

Posted: Tue Apr 22, 2014 7:45 am
by Albert Wiersch
If you have href="../../../index.html", then it is recommending that you replace it with href="../../../", not with href="./".

I would also be amazing if you could replace href="../../../index.html" with href="./". :D

If that works, then there must be a good reason why it's working in your case.

Re: ./ = index.html

Posted: Tue Apr 22, 2014 1:10 pm
by roedygr
I have done a number of experiments and I found ./ only works in the root directory. Elsewhere you must use ../.././ etc.

I could not repeat my strange results of jumping home successfully with ./ from E:\mindprod\jgloss\jgloss.html

The catch is, browsers don't understand what it means when serving the website from local files -- what you do when composing or when you distribute mirrors. I had to put it all back to index.html (not hard, all the code was in one spot).

If you were very keen on using it, you might use a local Tomcat server running on your own PC whose job is to make the website behave identically locally and on the web, including ads, google 1+ etc.

The essay htlml validator directed me to made it sound as if you could put ./ on ANY page at any depth and it would go home. For that to work, there would have to be some mechanism for a browser to figure out which directory is home. I could not find one.

I work with urls of the form jgloss/jdk.html in my markup and mechanically convert them to ../.. relative links.
The corresponding url on the website is
The corresponding local file is called e:\mindprod\jgloss\jdk.html

I have often wished I could directly use urls like /jgloss/jdk.html in my markup, but they do not work.
Does that format have an official name?

Have you ever thought of a mechanism so that a browser could handle a local website with more aplomb.
There would be a file you configure to use the files for local use. It would contain things like
where the home directory is.
where the corresponding web version is.
the extension to mime tables.

Re: ./ = index.html

Posted: Tue Apr 22, 2014 7:33 pm
by Albert Wiersch
Yes, this is limited to working with web servers and will likely not work if the HTML is being viewed locally from a local file system without a web server.

A path that starts with '/' is not relative to the current document but you might say it's relative to the site's root. I'm not aware of any official name for this type of path though. Maybe a "root relative" path?

I'm not sure what you mean by a mechanism for a browser to handle a local website better, but CSE HTML Validator has a path mapping feature so you can create some path maps for it to be able to properly resolve absolute link paths for link checking.