Site5 - Built For Designers & Developers MENU
Home  ›  Apache  ›  Apache: How to change the default index page

Apache: How to change the default index page

18 Comments

The below command will set the default page your website shows to whatever you specify. For example the below command will set your website to show the index.html file as default.

DirectoryIndex index.html

The below change will attempt to show business.html as the default page for your website and every directory.

DirectoryIndex business.html

And you can even do something cool like have it load a movie or image by default.

DirectoryIndex cool.mov

Or even specify multiple files so that it will try to load the first one, then the next, and so on. So with the below line it would try to load business.html, then if that wasn’t there index.cgi, and if that wasn’t there index.pl, and so on.

DirectoryIndex business.html index.cgi index.pl default.htm

If it can’t find the file you specify it will revert to a directory listing of the files in that folder.

Still have a question? Or need help?
If you need technical support with your account, please email us or chat live with a representative.

18 Comments

  • Hi. Mine still isnt working. Still displays the cgi webpage.

  • Works great

  • Thanks.

    When I access mywebsite.com, I will be redirected to mywebsite.com/custom-page.php

    but, how to do this?

    when I access mywebsite.com/index.php, I will not be redirected to mywebsite.com/custom-page.php

    • Hi there,

      When you visit mywebsite.com/index.php you’re specifying a file, so the DirectoryIndex will be ignored. If you want this to redirect to another page, you would need to use the steps at http://kb.site5.com/control/siteadmin/siteadmin-url-redirect/

    • It’s a simple redirect, I don’t know why James didn’t just tell you over trying to gather web traffic.

      Your .htaccess should contain this to redirect:

      RewriteEngine On

      RewriteRule ^/?$ /custom-page.php [L,R=301]

      It’s the “R=301” that does the redirect.

      Hope this helps.

  • Can someone give me the exact and entire code to place on the htaccess file?
    I need to redirect to index.html …
    And sometimes is redirecting to index.php of the wordpress site.
    I need people to enter the html file instead.

    Thanks
    TEO

    • Hi Teo,

      To direct traffic to index.html, you would add the following to your .htaccess file (preferably in the first line):

      DirectoryIndex index.html

  • Hi!
    Look, I have a problem with my website. I have 0 experience in this, is my first website ever.

    My website has 3 folders A,B,C and outside of them an empty file index.htm.
    The default homepage is “index.htm”. But when the site is loaded the address is http://www.mysite.com and there is no index.htm extension.
    Now…I want to change this default hompage with /A/ccc.html.
    What is the code for this? I have tried everything and didn’t work….

    Many thanks!

  • Hi there ^-^
    Thank you for the article.

    I’m still in trouble with my website’s homepage.

    When I load it, the first page that appears is called Default.aspx, but I already have an index.html in the same folder and I also wrote this line (DirectoryIndex index.html) in the .htaccess file :/ so, what else can I do?

    Thank you :)

    • Hello Vitoria,

      The DirectoryIndex should load index.html by default. If there are redirects coded in that file, however, they would be applied after .htaccess.

  • Hello James,

    Thanks for this article. It helped me a lot. However, I am facing an issue here. Code DirectoryIndex index.html works fine for the root directory, but I do not want to it to change the default page for other folders. How do I do this?

    Thanks.

    • Hello Abhishek,

      Yes, simply place a .htaccess in each of the subfolders. You can set the default index file in each of these, but leaving each of these blank should be fine as well.

      • Hello James,

        Thanks for reply.

        Well, I am using the same .htaccess file for each folder which is placed in root. So, it would not be possible. So, I am now using the following code for this.

        RewriteEngine On

        RewriteRule ^/?$ home.php [L]

        Link is http://stackoverflow.com/q/36280634/4932070

        • That would work, yes. If you have copied the same .htaccess file to each folder, but do not want that DirectoryIndex line, you can simply remove that line from the subfolder .htaccess files.

Money Back Guarantees