AnOwnSite header

htaccess lets you easily change the default page in a directory.


htaccess default directory page

You can use htaccess to change the default directory page. That's the page that comes up when the URL of a directoy is requested, like http://www.anownsite.com/webmaster-resources.

Why would you need such a change of the default directory page?

Good question. Here a great answer.

When I was doing webpages with an extension .html I wanted to put those parts of the pages that were always the same in a separate file and call that file within the page whenever I needed it.
The only way to get that working was to use server side included and that would only work if I renamed all my pages to .shmtl.

The first thing I had to do was to change my default directory page, because index.html, that was my default until then, did show up whenever someone addressed a directory on my site. For the .shtml to show up, I had to use htaccess!

Similarly you can have pages with an extension .php look like if they're html. Just use your htaccess file.

Here's how to change the default directory page:
DirectoryIndex filename.extension
The above line would have filename.extension to be the default directory page. You can name it default.php or case.shtml or whatever.

If you want multiple pages to show up, then the code would be:
DirectoryIndex filename.extension filename.html filename.php filename.shtml filename.htm
If your directory is addressed, the server will look for filename.html and if that one isn't there, filename.php and then filename.shtml etc.

Mind you, that there's also an option in Cpanel that does this. Don't overwrite any lines in your htaccess file by not downloading it first if you use Cpanel, or you may wipe IP blocking out.


Click to return to htaccess possibilities