Jesin's Blog

Welcome to the Portal of Technology

  • Facebook
  • GitHub
  • Google+
  • RSS
  • Twitter
  • Home
  • Categories
    • Domains
    • Linux
    • Networking
    • PHP
    • Virtualization
    • Web Design
    • Web Servers
    • Windows
  • WordPress Plugins
    • Custom Error Pages
    • HTTP Digest Authentication
    • Mailgun Email Validator
  • Toolbox
    • DNS Lookup Tool
    • htdigest Generator Tool Online
    • htpasswd Generator Tool Online
    • HTTP Headers Lookup Tool
    • MD5 Encryption Tool
    • Open Port Check Tool
    • SHA-1 Encryption Tool
    • URL Encoding/Decoding Tool
  • About Me
  • Contact Me
  • Sitemap
Home ›
Web Servers ›
Change the default Directory Index in Apache Server

Change the default Directory Index in Apache Server

August 22, 2010 Web Servers Jesin A Leave a Comment

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).

Related posts:

disable directory listing apache thumbnailDisable Directory Listing in Apache Default ThumbnailHow to create custom error page in Apache Default ThumbnailUsing the Apache Redirect directive Default ThumbnailSetting a Timezone in PHP Default ThumbnailRunning PHP code in HTML files

Tags: directoryindex, htaccess

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Get a wealth of information delivered to your inbox. Subscribe and never miss a single article.

  • Tutorials and howtos
  • Code, scripts and commands
  • Online Tools

* No spam, unsubscribe anytime

Hire Me

  • SSL installation and hardening (A+ on Qualys SSL test)
  • Apache & Nginx configuration
  • Email deliverability improvement (10/10 on Mail Tester & MailGenius)
  • WordPress customization, optimization and migration
  • and much more…

    Tools

    • DNS Lookup Tool
    • htdigest Generator Tool Online
    • htpasswd Generator Tool Online
    • HTTP Headers Lookup Tool
    • MD5 Encryption Tool
    • Open Port Check Tool
    • SHA-1 Encryption Tool
    • URL Encoding/Decoding Tool

    Nav

    • Home
    • About Me
    • Contact Me
    • Privacy Policy
    • Sitemap
    Vultr SSD VPS

    Creative Commons License
    Jesin's Blog by Jesin A is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
    Based on a work at websistent.com.