Our Internet browsers request files from Web servers, and the Web server gives it to us, if it can. Frequently, we only request a directory and do not specify any particular file. In such a case, the web server frequently returns a default file, like index.html. This helps our URLs to look cleaner and shorter and is especially handing when going to a website’s home page.
When we type in any website’s address like www.mywebsite.com into our web browser, we are really asking for the root directory of a web server identified by that name.
But do we really want to see the directory content? No! We want the home page, which is just a single file. So how does the web server know WHICH file to give us, since we only requested the root directory? Well, that’s where default files come in.
Basically, whenever we request a directory from a web server and do not specify a file, the web server will see if a default file exists in that directory (it doesn’t have to be the root directory). If a default file exists, then the webserver will return a default file. If not, it will return a view of the directory contents (or an error message depending on the permissions for that particular directory).
Probably the most common default file is index.html. But there are others, like index.php and default.asp, for example.
Let’s look at some examples.
| Specified URL | Returned File |
|---|---|
| http://www.mywebsite.com/ | mywebsite.com/index.html |
| http://www.mywebsite.com/products/ | mywebsite.com/products/index.html |
A home computer is NOT a web server. So, if you are designing a website and want it to work correctly on a home computer, the computer will not look for default files, which means that you will have to specify files in all the URLs in all your links.
You can still use relative URLs, you just can’t request directories and expect the computer to return files.
Another option is to install web server software on your computer.