How to Change Apache 2 Index.html
When a website visitor types a URL into their browser that points to a directory but does not contain a page name, Apache 2 searches through the directory to find the first file matching a name from its "DirectoryIndex" directive. By default, the first file Apache searches for is named "index.html," but this can be changed to another filename such as "index.php" to run a PHP file, for example. The Apache module "mod_dir" processes the "DirectoryIndex" directive, which is one of the core Apache modules and so enabled by default on Apache server installations.
Instructions
-
-
1
Log in to the remote server through SSH, or open a terminal window if you are located with the server.
-
2
Type "cd /etc/apache2" at the terminal prompt to change to the Apache 2 directory where the configuration files are stored.
-
-
3
Open "apache2.conf" in a text editor such as vi, pico or nano. Search for the "DirectoryIndex" line, which will look similar to the following:
DirectoryIndex index.html index.cgi index.pl
-
4
Edit the line to include new filenames, or remove existing pages. For example, you could change the directive to:
DirectoryIndex index.php index.htm
Files are searched in the order which they appear, so the first file matching a name in the list will be displayed to the visitor. Save the file and close the text editor.
-
5
Restart Apache by typing "/etc/init.d/apache2 restart" at the terminal prompt.
-
1
Tips & Warnings
If you do not have access to the configuration files on the server, it may be possible to add the "DirectoryIndex" directive to a .htaccess file if these are permitted by the Web host.
On some Linux distributions, the "DirectoryIndex" directive is in a separate configuration file. For example, in Ubuntu the directive is in the /etc/apache2/mods-available/dir.conf file.
References
Resources
- Photo Credit Thinkstock Images/Comstock/Getty Images