How to modify the .htaccess default index page

September 12, 2024 / cPanel & WHM

This article explains how to modify the .htaccess default index page.

When visiting a website by entering only its domain name, the default index page is the first page that loads. If multiple index files are present, the server follows a default order: index.php, index.html, index.htm, and default.htm.

To set a custom index page, you can modify the .htaccess file, especially useful if your index file has a customised name. This prevents internal links on your site from breaking.

Follow these steps to change your default index page using .htaccess:

  1. Log in to cPanel.
  2. Select the “File Manager” option under the “Files” tool.
    files>file manager
  3. Click on the “Settings” button from the right side of the screen.
    settings
  4. Choose the “Document root for” the domain you are using, and make sure “Show Hidden Files (dotfiles) is ticked in the checkbox next to it. Press the “Save” button.
    save
  5. Locate the “.htaccess” file, right-click on it, and click on the “edit” button.
    edit
  6. Paste the following code at the start of the .htaccess editor, substituting mypage.html with the name of your custom index file:
    #Alternate default index page
    
    DirectoryIndex mypage.html

    Note: If necessary, you can list more than one file. They will be inspected by the server left to right. The server will look for mypage.html first if index.htm, index.html, and index.php are added to the code. It will go to index.htm if it can’t find it, and so on.
    edit

  1. Click “Save Changes” finally.
    save changes

This way, you can modify the .htaccess default index page. If you need extra assistance, feel free to reach out to our support team.

Need more control over your directory listings? Check out How to Use the Index Manager in cPanel

Spread the love