For years after the internet became widespread, technology changed tremendously. From snail pace dial-up to lighting fast broadband and static bland web pages to dynamically changing websites with over the top eye-candy everything changed within the blink of an eye. But what we see throughout most of these websites is that the home page is named as index.html or index.php/.asp
It seems web programmers got so accustomed to old fashion ways of file names. One more thing to note, if you divide your website into several categories using directories e.g. http://website.com/category1 , category2 …. and have items within each category like http://website.com/category1/item1 , item2 ….. you would expect item1 to be displayed if a user enters http://website.com/category1/ By default you’ll need to name the item1 webpage as index.html. Whay not use the desired file name and tell Apache to treat it as an index file? Well that is what we’ll be doing in this article.
Method 1:- Edit the httpd.conf file
This method is suited for someone who uses a dedicated server/VPS. Open the httpd.conf file using a text editor and search for the following line.
<IfModule dir_module>
DirectoryIndex index.html index.htm index.php
</IfModule>
Add the file names at the end of the second line with a space. Take a look at the following example
<IfModule dir_module>
DirectoryIndex index.html index.htm index.php home.html myname.php jesin.htm
</IfModule>
In this way you add all the desired file names. Finally save the file and restart Apache Server. If it refuses to start then check for syntax errors.
Method 2:- Create/Edit .htaccess File
This method is for the most of us who host our websites on a shared server. Create a file named .htaccess (the dot at the beginning of the filename is very important) inside the www or public_html or htdocs folder. If it already exists edit it and add the desired filenames. For example
DirectoryIndex newfile.html item1.php
Save the htaccess file. You can also do this for specific directories by creating htaccess files inside specific directories and inputting the desired filenames. If you get a “500 Internal server error” check the syntax of the htaccess file.
Test your new configuration by placing a file of the name specified in the DirectoryIndex list.
Note:- Apache Server gives priority according to the order in which the filenames are entered. In the above example if you have two files named newfile.html and item1.php the former (newfile.html) will be displayed as it has more priority over the latter (item1.php).
Leave a Reply