Using the DirectoryIndex property in .htaccess to improve search engine optimization and web site manageability
How it’s used:
Enter a line in your .htaccess file similar to the following:
DirectoryIndex example.php
Special Notes: This works with the Apache Web Server and does not work with IIS. When editing the .htaccess file in a text editor, make sure “text wrapping” or “wrap text” is turned off. Using “text wrapping” or “wrap text” will cause the .htaccess file to fail.
What it does:
Allows a developer to choose which file to use as the default file when a directory or a web site loads.
Why you should use this property:
Improve Search Engine Optimization:
- Allows a developer to give a meaningful name to a “default“ file.
- Allows a developer to inject keywords into the URL.
Compare the following URLs.
http://thewidgeturl.com/index.html
http://thewidgeturl.com/free_widget_downloads.html
The second URL allows the developer to inject keywords (free widget downloads) into the URL to improve search engine optimization. The second URL’s file name is a better descriptor as compared to the file name, “index.html”.
Better site manageability:
By setting the DirectoryIndex property it allows a developer to control which file loads in a directory or which file is loaded when the web site’s root/homepage is accessed even if a hosting provider changes this property in the web server configuration files.
For example, your hosting provider may allow you to use a file named “index.php” to load when a directory or a web site is loaded. Think of the following URL, http://thewidgeturl.com. In the root of the website is a file named index.php and this file loads as the homepage. This works great, but, one day your hosting provider decides to change its policy and changes its web server configuration files to only load files named, index.html or index.htm when a directory or a web site loads. Now, when a user visits your homepage, the web server looks for the files, index.html or index.htm, the files cannot be found and a 404 error is displayed to every visitor of your homepage – not good.
These are only two of the advantages of using the DirectoryIndex property in .htaccess. For more information on .htaccess and the DirectoryIndex property visit the Apache website.
Check out all of our articles on search engine optimization and .htaccess
URL Rewriting with .htaccess and Apache to boost Search Engine Optimization
URL Rewriting with IIS (Internet Information Services)
Search Engine Optimization and 301/Permanent Redirects





[...] Using the DirectoryIndex property in .htaccess to improve search engine optimization and web site ma… [...]