GoAdmio

directoryindex

Show or set the default index files for the whole server (Apache DirectoryIndex and Nginx index)

On this page: Overview · Quick start · Syntax · Arguments · Output · Examples · Troubleshooting · Details · See also


Overview

When a visitor opens a folder URL such as https://example.com/, the web server looks for an index file to show. /go/directoryindex sets the list of file names it looks for, and the order. The first file in the list that exists is served.

The command:

A domain whose own virtual host or .htaccess file sets a different list is not controlled by this command.


Quick start

# Show the current Apache value
/go/directoryindex return

# Set the list (order matters)
/go/directoryindex index.php index.html

# Reset to the GoAdmio default list
/go/directoryindex

Syntax

# Show the current value
/go/directoryindex return

# Set the list
/go/directoryindex <file> [<file> ...]

# Use the default list without index.htm
/go/directoryindex default

# Reset to the default list
/go/directoryindex

Run the command as root.


Arguments

Argument Required Notes
return No Prints the current Apache value and changes nothing. Not case-sensitive.
<file> ... No One or more index file names, separated by spaces. The first existing file wins. Use plain file names only.
default No Sets default.html index.html index.php go.html.
(none) No Sets default.html index.html index.htm index.php go.html.
--noreload No Intended to skip the reload, but it has no effect. The web server is always reloaded.

If the first argument starts with --, it is ignored and the full default list is set.

Write file names only, such as index.php. Characters such as /, &, and \ break the edit.

[!NOTE] The command writes all of its arguments into the configuration. Don't add --noreload after the file names, or it ends up in the list as a file name.


Output

When setting a value, the command prints nothing of its own. Any output comes from reload.

With return, it prints the Apache value, for example:

default.html index.html index.htm index.php go.html

It then exits with status 1, even though nothing went wrong.

Message Meaning
Unknown operating system. The OS is not AlmaLinux, Rocky, CentOS, Red Hat, Fedora, Debian, or Ubuntu. Nothing is changed.

Examples

# PHP sites first, then static pages
/go/directoryindex index.php index.html index.htm
# Reset to the defaults
/go/directoryindex
# Check the Apache setting (AlmaLinux, Rocky, CentOS, Red Hat, Fedora)
grep -n '^[[:space:]]*DirectoryIndex' /etc/httpd/conf/httpd.conf

# Check the Apache setting (Debian, Ubuntu)
grep -n '^[[:space:]]*DirectoryIndex' /etc/apache2/mods-enabled/dir.conf

# Check the Nginx setting
grep -n '^[[:space:]]*index' /etc/nginx/nginx.conf
# Validate the configuration after a change
/go/checkapache
/go/checknginx

Troubleshooting

Symptom Likely cause Fix
return prints odd text instead of file names It reads the first line that contains DirectoryIndex, which can be a comment in the config file. Check the real value with the grep example above.
return is empty on an Nginx server return reads only the Apache configuration. Check Nginx with the grep example above.
A site ignores the change The site's virtual host or .htaccess sets its own list. Change it there, or remove that setting.
Nginx on Debian or Ubuntu ignores the change The command edits /etc/nginx/nginx.conf, not /etc/nginx/sites-available/default. Edit the Nginx file that holds the index line by hand.
--noreload doesn't stop the reload The option is not recognized, so the reload always runs. Expected.
The web server fails to reload after a change The value contained characters that made the configuration invalid. Reset with /go/directoryindex, then validate with checkapache or checknginx.
sed: can't read /etc/nginx/nginx.conf on an Apache server The command edits both configurations, whichever web server is installed. Expected. It can be ignored.
Unknown operating system. The OS is not supported. Edit the configuration by hand.

Details

Files it changes

Operating system Apache file Nginx file
AlmaLinux, Rocky, CentOS, Red Hat, Fedora /etc/httpd/conf/httpd.conf /etc/nginx/nginx.conf
Debian, Ubuntu /etc/apache2/mods-enabled/dir.conf /etc/nginx/nginx.conf

On Debian and Ubuntu, mods-enabled/dir.conf is normally a link to mods-available/dir.conf. Editing it in place can replace the link with a regular file.

Default lists

Form Value written
No arguments default.html index.html index.htm index.php go.html
default default.html index.html index.php go.html

What it does

flowchart TD
    A["directoryindex [return or files]"] --> B{"Supported OS?"}
    B -- "No" --> X["Print Unknown operating system"]
    B -- "Yes" --> C{"First argument is return?"}
    C -- "Yes" --> D["Print the Apache value, exit 1"]
    C -- "No" --> E["Work out the new list"]
    E --> F["Replace DirectoryIndex lines in the Apache file"]
    F --> G["Replace index lines in nginx.conf"]
    G --> H["Reload with the reload command"]
  1. Appends the call to /var/log/go/directoryindex.log.
  2. Picks the Apache file for the OS.
  3. With return, prints the Apache value and stops.
  4. Otherwise works out the new list: the defaults, or the arguments as typed.
  5. Replaces every line in the Apache file that starts with DirectoryIndex. Comment lines are left alone.
  6. Replaces every line in /etc/nginx/nginx.conf that starts with index, adding the closing ;.
  7. Runs reload.

The command only replaces lines that already exist. If a file has no DirectoryIndex or index line, nothing is added to it.

Side effects


See also

Command Description
reload Reload PHP-FPM and the active web server
checkapache Validate the Apache configuration
checknginx Validate the Nginx configuration and remove vhosts with no site directory
conf Rebuild the Apache/Nginx configuration in GoAdmio
apache Convert a GoAdmio server from Nginx to Apache
nginx Convert a GoAdmio server from Apache to Nginx
directory Password-protect a directory with HTTP Basic authentication, or remove the protection