Apache: DirectoryIndex for adding “index” file types

Some circles would have you believe that web sites should be written in one scripting language. That does not hold water when you consider all the applications that will need to be integrated into the web site. We have also experienced some application developers that will place an “index.html” file that calls the other file. I have to assume their training was in web languages and they have no experience with Apache web server.

Take for instance you are a beginner with web page design and want to use the default first page, “index.html.” As you progress you may want to create other web applications that require “index.php”, “index.wml” or “index.pl.” Do not be afraid to expand your horizons, because Apache is very flexible.

The easiest method for accomplishing this task is with Apache’s “.htaccess” file. Apache will read the .htaccess file prior to performing any work within the directory. The lowest level .htaccess file found is applied to the directory and sub-directories. So, we will need to work with the .htaccess file at the lowest directory we want the directions to apply.

Recently, we set up a mobile directory which included an “index.wml” file. Hosting plans will not allow you to get to the root of their Apache web server to make modifications, so we needed to take care of the problem within the mobile directory.

We created the .htaccess file and placed the following Apache web server instructions:

DirectoryIndex index.wmlsc index.wml
AddType text/vnd.wap.wml .wml
AddType image/vnd.wap.wbmp .wbmp
AddType application/vnd.wap.wmlc .wmlc
AddType text/vnd.wap.wmlscript .wmls
AddType application/vnd.wap.wmlscriptc .wmlsc
AddHandler cgi-script .wmlsc

This enabled us to create a mobile directory and implement an “index.wml” file for interpretation by the web server. Please note that too many .htaccess files will slow the performance of the web server and you also want to be careful not to over ride any previous directives. Oh, and don’t forget to check the permissions on the .htaccess file because you do not want anyone but “root” to be able to write to the file.

Hope this helps,

Mike Kniaziewicz

Comments are closed.