Index.html

I am learning javascript using tutorials on line. I have a question about handling code files on my pc. Specifically, index.html. Must this file be called index or can it be called for example myProgram.html in a folder called myProgram. Or must index.html be in a folder called myProgram. I hope my question is clear. Thank you, Roger

You can name your files and folders anything you want. Their names dictate how you access them through a URL in your browser’s location bar.

There IS significance to some names, such as index.html. Many server configurations use this name - or others, like index.php, or default.htm - as a file to load if you open up a URL path that directs to a folder rather than a file. So, for example a file URL would be:

[fake] www.regor.com/myProgram/myProgram.html

whereas the folder URL would just be

[fake] www.regor.com/myProgram/

If you have a file named index.html inside the myProgram folder, the folder URL above would load index.html without requiring it be in the URL. If you don’t have a file there, the server can decide to put whatever it wants there. For example it can show a list of files in the directory, or it can restrict you from seeing anything at all. On my server I have examples of this. First, an automatic listing of files in a folder generated automatically by the server:

http://senocular.com/pub/kirupa/

Then there’s this folder which has an index.html file in it. The list is no longer seen because it loads the index.html file instead.

http://senocular.com/pub/kirupa/has-index/

And finally this folder doesn’t have an index.html, but there is a server configuration that prevents the automatic file listing from being seen:

http://senocular.com/pub/kirupa/denied/

Servers can be configured to use a file by any name as their “index” page. You could set it up to be myProgram.html if you wanted, but generailly people stick to using index.html as its a standard that pretty much everyone uses. What’s nice about using index pages is that you can change them without changing your URL. For example you can tell people to go to

[fake] www.regor.com/myProgram/

to use your program which may have started in index.html. But if you change your program to use PHP instead, you may want to load a php file instead of html. This is easily done by using an index.php file in the myProgram folder instead of index.html. But if you told people to go to

[fake] www.regor.com/myProgram/myProgram.html (or index.html)

then you’re stuck with a URL that explicitly calls out to an HTML file and you’d need to give people a new URL if switching to PHP (though there are other solutions such as using redirects etc, but you get the idea).

1 Like

Thank you Senocular. You helped me most by pointing out that index.html is a convention that people use and that’s the first time I have noted that. I may be tackle PHP after I get my head around the javaScript code. Bye for now, Roger