Don’t miss the New Year’s Sale deals!
search
In this article

How to use directoryindex and .htaccess to change your website’s default index page

In this article, we will show you how to change and modify the first page of your website using the DirectoryIndex command in the .htaccess file. Let’s check it out!

How does the index file work?

When you open a website on any browser, a typical web server will look for a file called index.html or index.php in its public_html files to load and deliver that file’s content to your browser.

DirectoryIndex is a command that lets you modify the index files of your website easily in the .htaccess file. It’s used to specify which files should be loaded first by the page when your website is accessed.

You can also set up a second, third, and more files to be loaded by the server next in case there’s any error preventing the designated first page to load.

Locating and accessing the .htaccess file

The first thing you need to do is locate or create a new .htaccess file in the WordPress root directory or in our case, public_html. Here’s how:

  1. Login to Hostinger’s hPanel, so to your site’s dashboard, and navigate to Files File Manager.
  2. You can also configure an FTP client such as FileZilla to access the directory from a local computer.
  3. Once you’re in the public_html directory, locate the .htaccess file. If it doesn’t exist, you can quickly create one by going to the upper part of the page and selecting the New File function.
    this image shows you how to create a new htaccess file in File Manager
  4. Once you’re prompted with a file creation box, enter .htaccess, then press Create to save the file.

It’s worth mentioning that locating the .htaccess file on cPanel follows a similar process.

Editing .htaccess to add the DirectoryIndex command

To modify the first page loaded by your website using the DirectoryIndex command, follow these steps:

  1. Head to .htaccess and right-click to Edit.
  2. Paste the following code at the top of the file to configure your desired index page:
DirectoryIndex example.html

Remember to replace example.html with the page you want to use.

You can also list more than one file in the configuration. In this example, we add first.html, index.html, and index.php to the list.

this image shows you an example of directoryindex input in .htaccess

Your specified index files will be read and checked from left to right. First, the server will look for first.html, and if it doesn’t find a file with that name, it continues to index.html and so on.

You can also use this command to set up a temporary error page where your visitors will be directed to in case your page unexpectedly crashes. Here’s an example:

DirectoryIndex index.php page-down.php

Once the desired code is added, don’t forget to save the changes, and the configuration will take effect.

Congratulations, you have successfully changed the default index page of your website by manipulating the .htaccess file!

Hostinger web hosting banner

Conclusion

In this tutorial, we have learned how to effectively change the first page on your website using DirectoryIndex in the .htaccess file. In case you have any other cool tips that you want to share with us, you are welcome to do so in the comments!

Author
The author

Merkys M.

Merkys is a server administrator and Linux expert. He keeps everything up & running while tackling advanced server management issues. Besides that, he’s a big fan of blockchain technology, web development, and bodybuilding.

What our customers say

Comments

Author
Patience IGIRANEZA

August 19 2020

I have bought a domain name, my home page is yous. How to change it?

Author
Bob F

September 02 2020

This was helpful, thank you!

Author
Keith

December 24 2020

How about what if I want to set another folder in public_html as default instead of public_html. I want to setup public_html/production as default instead of putting files in public_html. Thanks for answering :)

Author
Athour

December 11 2021

Hi team, i have developed my website from Asp.net. And it's Startup Page is 'default.aspx' when i put the name in directory index command Like "DirectoryIndex Default.aspx" in .htacces file its does not work. when i refress my webpage 403 Error. my question is how can i set startup page is default.aspx Please help me ! Thanks in advance

Author
Mousmi Guru

January 16 2022

my website show, this " Website x.com has been successfully installed on server! Please delete the file default.php from the public_html folder and then upload using ftp or file manager " how to fix it

Author
Ogo Isaac

September 13 2022

I can't setup my blog, i bought a domain from non google registry and i'm trying to my new hosting but it's giving me a whole lot of problem please help me out.

Author
Jim Meyers

June 02 2023

I created my website by copying HTML files from another. It works fine but when I edit 'index.html' and save changes they don't show on my website. The changes are in the file I saved.

Leave a reply

Please fill the required fields.Please accept the privacy checkbox.Please fill the required fields and accept the privacy checkbox.

Thank you! Your comment has been successfully submitted. It will be approved within the next 24 hours.