htaccess

How to Change the Default Index Page Using directoryindex and .htaccess

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 it 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 through .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 other files to be loaded by the servers next in case there’s any error causing the designated first page to load poorly.

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 and navigate to the File Manager located under the Files area.
  2. You can also configure an FTP client such as FileZilla to access the directory from a local computer.
  3. Once you’re in public_html directory, scroll down and 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 with 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!

Conclusion

In this tutorial, we have learned how to effectively change the first page on your website using directoryindex along with 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!

About the author

Merkys M.

Merkys is a server administrator and Linux expert at Hostinger. 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.

Add Comment

Click here to post a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Get Exclusive Content

Join thousands of webmasters who get our free newsletter with tips on how to drive more traffic and revenue to their websites!

Please wait...

Thank you for sign up!

More in htaccess
How to Allow or Block Visitors From Specific Countries Using .htaccess
Close