How To Add Custom DirectoryIndex Settings to Apache VHosts¶
Be default, the DirectoryIndex setting in the Apache vhosts created by InterWorx include index.html
and index.php
.
However, if additional index file extensions are required, it is possible to customize the vhosts to include them.
Customizing the DirectoryIndex settings for a single domain can be completed either with a custom conf file in the domain’s homedir, or via the InterWorx Config system.
Adding custom DirectoryIndex settings globally can be completed using the InterWorx Config System.
Using either method will allow the changes to persist if the domain is restored or imported from a backup.
Contents
To Update a Single Domain¶
The following examples will add index.htm as an accepted DirectoryIndex.
Using A Custom Conf file¶
Log in to the server at the CLI as root, either via SSH or from the terminal
At the CLI, navigate to the domain’s apache directory, replacing {unixuser} and {domain.com} with the corresponding information:
cd /home/{unixuser}/var/{domain.com}/apache
Using a text editor, create a file that ends in .conf. The following example uses the Vim test editor
Note
Since this example is adding
index.html
as an accepted DirectoryIndex, the file will be namedhtm.conf
. However, the only naming requirement is that the file ends with.conf
. The file can be named in any way, outside of that extension.vim htm.conf
Add the following line to that file, replacing {custom DirectoryIndex} with the corresponding information:
DirectoryIndex index.php index.html {custom DirectoryIndex}
Example:
DirectoryIndex index.php index.html index.htm
Save and exit the text editor
Reload or Restart Apache
systemctl reload httpd
or
systemctl restart httpd
Using the InterWorx Config System¶
Log in to the server at the CLI as root, either via SSH or from the terminal
Check the current DirectoryIndex settings for the domain with the following, replacing {domain.com} with the corresponding information:
~iworx/bin/config.pex --get --domain {domain.com} --name HTTPD_DIRECTORY_INDEX
Example:
[root@server ~]# ~iworx/bin/config.pex --get --domain example.com --name HTTPD_DIRECTORY_INDEX index.php index.html [root@server ~]#
Run the following command, replacing {domain.com} and {custom DirectoryIndex} with the corresponding information:
~iworx/bin/config.pex --set --domain {domain.com} --name HTTPD_DIRECTORY_INDEX --value 'index.php index.html {custom DirectoryIndex}'
Example:
[root@server ~]# ~iworx/bin/config.pex --set --domain example.com --name HTTPD_DIRECTORY_INDEX --value 'index.php index.html index.htm' [root@server ~]#
Check that the changes were made successfully, replacing {domain.com} with the corresponding information
~iworx/bin/config.pex --get --domain {domain.com} --name HTTPD_DIRECTORY_INDEX
Example:
[root@server ~]# ~iworx/bin/config.pex --get --domain example.com --name HTTPD_DIRECTORY_INDEX index.php index.html index.htm [root@server ~]#
Rewrite the vhost file for the domain, replacing {domain.com} with the corresponding information
~iworx/bin/httpd.pex --write-vhost --domain {domain}
Reload or Restart Apache
systemctl reload httpd
or
systemctl restart httpd
To Set a Custom DirectoryIndex Globally¶
Note
This will add the custom DirectoryIndex both to existing vhosts, as well as the vhosts for any newly created domains on the server.
The following examples will add index.html as an accepted DirectoryIndex
Log in to the server at the CLI as root, either via SSH or from the terminal
Check the current DirectoryIndex settings for the domain with the following:
~iworx/bin/config.pex --get --global --name HTTPD_DIRECTORY_INDEX
Example:
[root@server ~]# ~iworx/bin/config.pex --get --global --name HTTPD_DIRECTORY_INDEX index.php index.html [root@server ~]#
Run the following command, replacing {custom DirectoryIndex} with the corresponding information:
~iworx/bin/config.pex --set --global --name HTTPD_DIRECTORY_INDEX --value 'index.php index.html {custom DirectoryIndex}'
Example:
[root@server ~]# ~iworx/bin/config.pex --set --global --name HTTPD_DIRECTORY_INDEX --value 'index.php index.html index.htm' [root@server ~]#
Check that the changes were made successfully
~iworx/bin/config.pex --get --global --name HTTPD_DIRECTORY_INDEX
Example:
[root@server ~]# ~iworx/bin/config.pex --get --global --name HTTPD_DIRECTORY_INDEX index.php index.html index.htm [root@server ~]#
Rewrite all of the vhosts on the server
~iworx/bin/httpd.pex --write-vhosts-all
Reload or Restart Apache
systemctl reload httpd
or
systemctl restart http