How can OVHcloud shared hosting use a different directory index file?

The Citead team, updated

In short. Use DirectoryIndex in the applicable .htaccess file to select a different directory index file on OVHcloud shared hosting.

Definition: On OVHcloud shared hosting, DirectoryIndex in a .htaccess file selects the file served when a directory URL is requested. OVHcloud documents index.html, index.htm, and index.php as default index filenames and shows home.html as a replacement.

Key facts

  • OVHcloud describes .htaccess as an Apache configuration file run by the web server of a Web Hosting plan, with rules that can apply to a directory and its subdirectories. The OVHcloud operations guide gives this scope.
  • The same guide says to place only one .htaccess file in each directory or subdirectory.
  • OVHcloud lists index.html, index.htm, and index.php as the default index filenames in a directory.
  • Its example for a different file is DirectoryIndex home.html.
  • Apache documents .htaccess as a valid context for DirectoryIndex, with the Indexes override.
  • Apache says several resources can be listed, and the server returns the first one that it finds. The Apache mod_dir documentation defines this selection rule.

How does DirectoryIndex select the file?

DirectoryIndex is the Apache directive that defines the resources to look for when a client requests a directory with a trailing slash. Apache describes the value as a local URL relative to the requested directory, usually a filename. When several names are listed, the server uses the first existing resource in that order.

For an OVHcloud directory that should open home.html, the guide shows this line in .htaccess:

DirectoryIndex home.html

The directive selects the resource for the directory request. It does not require the selected filename to be exposed in the requested directory URL. Apache documents the separate DirectoryIndexRedirect directive for redirect behavior.

Which filenames does OVHcloud document by default?

OVHcloud's guide says that the default index file in a directory is index.html, index.htm, or index.php. The wording identifies the filenames documented for its Web Hosting guidance. It then instructs the reader to add a DirectoryIndex line in .htaccess when another file should be used.

The guide's generic form is:

DirectoryIndex File_Name

The placeholder is replaced with the filename to select. OVHcloud's concrete example replaces it with home.html, so the file named in the directive must be present at the directory location to be selected by Apache's lookup.

Where does the rule apply on shared hosting?

OVHcloud says that a .htaccess file can define rules for a directory and all of its subdirectories. The file is created in the directory where the rule should apply. Apache also lists directory and .htaccess among the contexts accepted by DirectoryIndex.

Because OVHcloud advises using only one .htaccess file per directory or subdirectory, a configuration should be checked for an existing file before another one is created. The documented rule applies to the directory containing that file and its descendants, subject to the hosting server's Apache configuration.

What happens when several index names are configured?

Apache permits several local URLs after DirectoryIndex and searches them in the order written. For example, the Apache documentation uses this form:

DirectoryIndex index.html index.txt /cgi-bin/index.pl

If the earlier resources are absent, Apache can continue to a later resource. If none exists and the Indexes option is enabled, Apache documents that the server generates a directory listing. OVHcloud separately documents Options -Indexes for preventing a listing when a directory has no index file.

FAQ

Can you use a filename other than the OVHcloud defaults?

Yes. Add DirectoryIndex followed by the selected filename to the .htaccess file in the applicable directory. OVHcloud's example uses home.html.

What if you list more than one filename?

Apache checks the listed resources in order and returns the first one it finds. A list can therefore provide a fallback after the preferred filename.

Does DirectoryIndex redirect the directory URL to the file?

Apache documents directory index selection as transparent to the client by default. Redirect behavior is described under the separate DirectoryIndexRedirect directive.

Sources

  1. OVHcloud, "Tutorial - Operations achievable with a .htaccess file", 23 May 2023
  2. Apache HTTP Server, "mod_dir - Apache HTTP Server Version 2.4", undated

Check how a page reads to answer engines. Open the GEO score analyzer

Test a page and see what to fix first

The analysis usually takes less than 10 seconds and needs no account.

400,000+ pages scored in the public benchmark