Apache Display / Change a Default Page Other Than index.html

How do I display or change a default page other than index.html or index.php under Apache web server?

You need to use DirectoryIndex directive under Apache to set a default page other than index.html or index.php.

Advertisement

The DirectoryIndex directive sets the list of resources or file to look for, when the client requests an index of the directory by specifying a / at the end of a directory name.

Edit httpd.conf

Open your Apache configuration file httpd.conf
# vi httpd.conf

Find out line that read as follows:
DirectoryIndex

Now set it as per your requirements:
DirectoryIndex index.html index.htm default.htm index.php index.pl

Save and close the file. Restart the Apache web server:
# /etc/init.d/httpd restart

Please note that if you do not have access to Apache configuration file. Add DirectoryIndex to your .htaccess file.

You can also specify php or pl dynamic script. Also note that the documents do not need to be relative to the directory. Consider following example
DirectoryIndex index.html index.pl /nav/index.php

Above would cause the php script /nav/index.php to be executed if neither index.html or index.pl existed in a directory.

🥺 Was this helpful? Please add a comment to show your appreciation or feedback.

nixCrat Tux Pixel Penguin
Hi! 🤠
I'm Vivek Gite, and I write about Linux, macOS, Unix, IT, programming, infosec, and open source. Subscribe to my RSS feed or email newsletter for updates.

17 comments… add one
  • praveen Jul 4, 2011 @ 9:34

    how I can make all my php pages extenions(.php) should be shown as html extension(.html). Is there any way I can change that to .php files to .html when client acces the php pages? Please resolve the issue as soon as possible. Thanks!

  • Mohsin Sep 18, 2012 @ 19:02

    Thanks Alot:)
    I really appreciate!

  • JK Apr 10, 2013 @ 5:58

    Thanks for the information. It really helps a lot.

  • Mrudula Apr 10, 2013 @ 11:55

    Wooooohhooooo…!!! It worked.. :)
    Thanks

  • lalitha Nov 20, 2013 @ 6:12

    how can i make this work if im hosting two webpages? using VirtualHost

  • Gunasekhar Jan 24, 2014 @ 10:31

    Thank u sir

  • luniga Mar 1, 2014 @ 6:14

    Thanks… it works

Leave a Reply

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

Use HTML <pre>...</pre> for code samples. Your comment will appear only after approval by the site admin.