# Changing the default directory index via .htaccess

> Choose which file loads first when a visitor opens a folder on your site by setting DirectoryIndex in .htaccess.

Source: https://helpcenter.ruachost.com/developers/web-servers/changing-the-default-directory-index-via-htaccess/

By default, Apache servers look for `index.html` when a visitor requests a directory (e.g., `http://example.com/products`). On **ruachost.com**, you can customize which file loads first by editing the `.htaccess` file.

## Why Change the Default Directory Index?

- Display a different file (e.g., `index.php` instead of `index.html`).
- Use multiple fallback options (e.g., `home.html`, `default.php`).
- Control how directories behave when no index file exists.
- Improve flexibility for CMSs or custom applications.

## Steps to Change the Directory Index

### Step 1: Open the `.htaccess` File

1. Log in via FTP, SFTP, or File Manager.
2. Navigate to your site’s root directory (`public_html`).
3. Open or create the `.htaccess` file.

### Step 2: Add the `DirectoryIndex` Directive

Insert the following line:

```
DirectoryIndex index.php index.html index.htm home.html
```

- Apache will look for files in the order listed.
- In this example, it will first try `index.php`, then `index.html`, then `index.htm`, and finally `home.html`.

### Step 3: Save and Test

1. Save the `.htaccess` file.
2. Visit your site in a browser.
3. Confirm the correct file loads when accessing a directory.

> **Important Notes:**
- Place the directive in the root `.htaccess` file to apply site‑wide.
- Subdirectories inherit the setting unless they have their own `.htaccess`.
- If none of the listed files exist, Apache will either show a **403 Forbidden** error or a directory listing (if enabled).
- Always back up your `.htaccess` file before editing.
