htaccess

How to Change Your Default Index Page in .htaccess File

.htaccess is a configuration file used on web servers running the Apache Web Server software. The server looks for specifically named files as the first page of your website, also known as the index page. For example, if you were to ask for www.example.com/about/, a typical web server will look for a file called index.html in the about folder of your website. If it exists, the server will deliver that page’s content to the browser. You can change the name of the index file your account looks by using directoryindex rule in your .htaccess file.

What you’ll need

Before you begin this guide you’ll need the following:

  • Access to Hosting control panel or FTP

Step 1 — Locating/creating and accessing your .htaccess file

First thing you will need to do is locate or create the .htaccess file. This can be easily achieved using the File Managers located in your hosting control panel or by using a FTP client such as FileZilla. In this tutorial, we will use Hostinger’s File Manager.

File Manager location in hosting control panel

You will be required to edit your existing .htaccess file or create a new one if it does not exist. An existing .htaccess file can be easily changed by clicking the right mouse button and selecting the Edit function from the dropdown menu as shown below:

Editing htaccess file via Hostinger File Manager

If .htaccess does not exist, you can quickly create it by right-clicking on an empty area inside File Manager and selecting the New File function.

Creating a new file

After that, you will be prompted with a file creation box, where you will need to enter the new file’s name. In this case, you will need to type .htaccess and press Create to save the file. Once that is done, you will be able to edit the newly file and add your code.

File creation screen

In case your hosting platform uses cPanel, you can reach the same goal by following this tutorial:

Step 2 — Editing .htaccess file

Once you have opened your .htaccess file using Edit function, paste the following code at the top of the page to configure your desired index page:

DirectoryIndex example.html

In our example below, we decided to make the index page of our folders named first.html, which means that the code in .htaccess should look like this:

DirectoryIndex first.html

You can also list more than one file in the configuration. Your specified index files will be read and checked from left to right. In this example, we add index.htm, index.html, and index.php to the list. First, the server will check for first.html, if it does not find a file with that name, it continues to index.htm and so on.

DirectoryIndex first.html index.htm index.html index.php

This can also have some nice practical uses. For instance, you may set up a temporary page where your visitors will be directed to in case your website unexpectedly crashes. Here is an example code:

DirectoryIndex index.php page-down.php

When using this configuration, the browser will first look for index.php. In case it may not be accessed, the next file to load would be page-down.php. Once the desired code is added, don’t forget to Save the changes and the configuration will start taking effect.

Save htaccess changes

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 .htaccess. We’ve also learned a few practical tricks that can benefit every developer at some point in time. In case you have any 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!