4. index file definition
Updated on February 14, 2026.
When browsing a website, a file name appears as part of the URL with each request. Example: For this page, the file name is Index-file.php. For example, on this page the file name is Index-file.php, located in the apache directory. However, if you enter the URL as:
https://www.science.co.il/internet/apache/
without specifying a file name, the page is displayed without showing any file name in the address bar. In such cases, the server automatically loads a predefined default file for that directory. This default file is called the index file.
Importance of Defining an Index File
Defining an index file is strongly recommended for two main reasons:
- Security:
If no index file is defined, the server may either:
• Display a list of all files in the directory (directory listing), or
• Return a 403 Forbidden error
Directory listing is generally undesirable. Over time, files may accumulate in a directory, and exposing them can reveal outdated, incomplete, or sensitive information. - Organizational clarity:
Websites are typically structured in a tree-like hierarchy, where directory names reflect the content they contain. Defining an index file ensures that each directory presents a clear and intentional entry point to its content.
On most servers, when a URL ends with a slash (/), the default file served is "index.html". Depending on the programming language used, the index file may have other names, such as index.php, index.pl, index.cgi, etc.
Defining index file in an Apache server
In Apache, the default index file name(s) can be specified inside the <VirtualHost *:80> block described on the virtual host configuration page for Apache.
If you already have an "enabled" configuration file, open it using:
sudo nano /etc/apache2/sites-enabled/example.com.conf
Within the <VirtualHost *:80> block add the following directive:
DirectoryIndex index.html index.htm index.php
This directive defines the order in which Apache searches for default files. In the example above, the server will first look for index.html. If it does not exist, it will look for index.htm, and only if neither of those files is found will it serve index.php.
After these changes, restart the Apache service using the command:
sudo systemctl restart apache2
Alternatives
The DirectoryIndex directive can also be placed in the configuration file .htaccess in the website directory.