How to Use directoryIndex and .htaccess to Change Your Site’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 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:
- Login to Hostinger’s hPanel and navigate to the File Manager located under the Files area.
- You can also configure an FTP client such as FileZilla to access the directory from a local computer.
- 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.
- 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:
- Head to .htaccess and right-click to Edit.
- 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.
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!
Comments
August 19 2020
I have bought a domain name, my home page is yous. How to change it?
November 06 2020
Hey there! :) If you have a hosting plan you can just upload the website here! :)
September 02 2020
This was helpful, thank you!
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 :)
February 09 2021
Hello Keith :) Try using this code in your .htaccess (in public_html):
RewriteEngine on RewriteCond %{HTTP_HOST} ^domain.com [NC,OR] RewriteCond %{HTTP_HOST} ^www.domain.com$ RewriteCond %{REQUEST_URI} !foldername/ RewriteRule (.*) /foldername/$1 [L]
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
December 14 2021
Hi, ASP.NET doesn't have .htaccess file, but you can make similar changes from web.config file - you can read more about it here and here.
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
January 18 2022
Hi there, if you see this message you can proceed with uploading your website files or installing the CMS you like. We have an awesome list of our favourite CMSes, if you'd like to check that out :) Once that's done and your website has an index.php or index.html file, the default message should be gone, as the index file will override the default.php. In case that doesn't happen, double check the permissions set for your index file and delete or rename the default.php file. It could happen that after disabling default.php, you'll see a blank page or a list of your files - that means there's an issue with your index file, so try and reset it to the default of your chosen CMS.
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.
September 16 2022
If you want to use a domain that was registered elsewhere with our hosting services, you should access your hosting provider's DNS zone and update the name servers to point to Hostinger. You can learn how to point your domain to Hostinger by reading this article ?
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.
June 02 2023
Hello there! There is a big chance that your browser cached up old version of your website. Have you tried clearing browser cache or checking the website on incognito mode of your browser?