Enable and Configure Auto Index¶
LiteSpeed Web Server supports automatic directory indexing when an index file is not present in a directory. It uses an external script to generate the index page on the fly. This provides you with maximum flexibility when creating the look and feel of your auto index page.
By default, Auto Index is disabled.
Auto Index can be enabled at the server level, virtual-host level, and context level. Each sub-level will override a parent-level setting. In other words, a context-level setting will override the vhost-level setting, and a vhost-level setting will override the server level setting.
If Auto Index is enabled, or when a directory with no index file is accessed, OpenLiteSpeed will perform an internal redirect to Auto Index URI. If the value is not set, the URI will contain the default value /_autoindex/default.php
.
Enable or Disable Auto Index¶
Server level¶
In the WebAdmin Console, navigate to Server Configuration > General > Index Files and configure the following settings:
- Index Files:
index.html,index.php
- Auto Index: Set to
Yes
to enable, set toNo
orNot Set
to disable - Auto Index URI: This is the script that is used to generate the index, and you can leave it blank to default to
/usr/local/lsws/share/autoindex/default.php
, or specify the location of your custom script
Virtual-host level¶
Navigate to Virtual Hosts > General > Index Files and configure the following settings:
- Use Server Index Files: Use
Yes
to inherit the index files named at the server level, useNo
to specify your own index files, and useAddition
to use the server-level files plus your own listed index files - Index Files:
index.html,index.php
- Auto Index: Set to
Yes
to enable, set toNo
to disable, or set toNot Set
to inherit the server-level setting - Auto Index URI: This is the script that is used to generate the index, and you can leave it blank to default to
/usr/local/lsws/share/autoindex/default.php
, or specify the location of your custom script
These settings will override the server-level configuration.
Context level¶
If you want to disable Auto Index for all except a few specific directories, you can achieve this with context settings.
Navigate to Virtual Hosts > Context and create a Static Context and configure the following settings:
- URI: Set the directory for this context to apply to (we've used
/test/
), and don't forget to add the/
at the end of the URI - Location: This can be an absolute path e.g.
/home/domain.com/public_html/test/
or a relative path with$DOC_ROOT
or$VH_ROOT
(for example$DOC_ROOT/test/
or$VH_ROOT/public_html/test/
) - Accessible:
Yes
- Index Files: Set the index file name for this context
- Auto Index: Set to
Yes
to enable, set toNo
to disable, or set toNot Set
to inherit the virtual-host-level setting
These settings will override the virtual-host-level configuration.
Customize the Auto Index Page¶
You can customize your index page globally at the server level, or at the virtual-host level.
The default script paired with the installation package is a PHP script. However, you can create your own script using any language you like. The default PHP script, located at lsws/share/autoindex/default.php
, has the same look and feel as Apache’s mod_autoindex.
When you write your own script, the path to the directory you’re indexing is passed to the script in a CGI environment variable: LS_AI_PATH
. In PHP, you can retrieve the value with the command $_SERVER[‘LS_AI_PATH’]
.
The script can be placed anywhere you like, but if you want to share it among all of your virtual hosts, just place it under the lsws/share/autoindex/
directory.
A General Context GUI with the URI /_autoindex/
and Location $SERVER_ROOT/share/autoindex/
is automatically created by OLS for every virtual host.
Server level¶
To create your own Auto Index Page globally, navigate to Server > General > Index Files and set Auto Index to Yes
.
Set Auto Index URI to the location of your own script, for example, lsws/share/autoindex/myindex.php
Tip
Do not modify default.php
directly, as it will be overridden after any upgrades. Your own script and configuration will not be affected by version upgrade.
Virtual-host level (Native)¶
Navigate to VHost > General > Index Files and set Auto Index to Yes
. Set Auto Index URI to the URI of your script.
Note
You cannot customize the index file at the virtual host level if the virtual host is configured through an Apache configuration file. In that case, you can only apply a customized index file at the global level.
Virtual-host level (Apache vhosts via control panel)¶
For Apache vhosts, the Auto Index URI can be set in .htaccess
with the LiteSpeed-specific directive:
<IfModule LiteSpeed>
AutoIndexUri /lsws/share/autoindex/myindex.php
</IfModule>