Module mod_dir

Module mod_dir supports directives for the IBM® HTTP Server for i Web server.

Summary

The module mod_dir provides "trailing slash" redirects and serving directory index files. The index of a directory can come from one of two sources:

  • A file written by the user, typically called index.html. The name of this file is set by the DirectoryIndex directive . This directive is controlled by module mod_dir.
  • A list generated by the server through mod_auto_index. See mod_auto_index for more information.

The two functions are separated so you can completely remove (or replace) automatic index generation.

By default, a trailing slash ('/') redirect is issued when the server receives a request for a URL http://servername/QIBM/dirname where dirname is a directory. Directories require a trailing slash, so mod_dir issues a redirect to http://servername/QIBM/dirname/.

The AlwaysDirectoryIndex directive controls how the server will respond to directory requests.

Directives

AlwaysDirectoryIndex

Module: mod_dir
Syntax: AlwaysDirectoryIndex disabled | local-url [local-url] ...
Default: Always DirectoryIndex on
Context: server config, virtual host, directory, .htaccess
Override: Indexes
Origin: IBM
Example: AlwaysDirectoryIndex off

The DirectoryIndex directive sets the list of resources to look for, when the client requests an index of the directory by specifying a / at the end of the a directory name. Local-URL is the (%-encoded) URL of a document on the server relative to the requested directory; it is usually the name of a file in the directory. Several URLs may be given, in which case the server will return the first one that it finds. If none of the resources exist and the Indexes option is set, the server will generate its own listing of the directory. For example:

DirectoryIndex index.html

A request for http://myserver/docs/ would return http://myserver/docs/index.html if it exists, or it would list the directory if it did not exist.

Note: The documents do not need to be relative to the directory. For example: DirectoryIndex index.html index.txt /cgi-bin/index.pl

This would cause the CGI script /cgi-bin/index.pl to be run if neither index.html or index.txt existed in a directory. This same idea will also work for QSYS.LIB files. For example, if the directory index is stored in /QSYS.LIB/MYLIB.LIB/MYFILE.FILE/INDEX.MBR, you would need to specify DirectoryIndex Index.mbr .

A single argument of "disabled" prevents mod_dir from searching for an index. An argument of "disabled" will be interpreted literally if it has any arguments before or after it, even if they are "disabled" as well.

The directive may be configured multiple times in a container. The directives are processed from the first to the last occurrence in the container.

DirectoryCheckHandler

Module: mod_dir
Syntax: DirectoryCheckHandlerOn| Off
Default: DirectoryCheckHandler Off
Context: server config, virtual host, directory, .htaccess
Override: Indexes
Origin: Apache
Example: DirectoryCheckHandler On

The DirectoryCheckHandler directive determines whether mod_dir should check for directory indexes or add trailing slashes when some other handler has been configured for the current URL. Handlers can be set by directives such as SetHandler or by other modules, such as mod_rewrite during per-directory substitutions.

In releases prior to IBM i 7.2, this module did not take any action if any other handler was configured for a URL(implicitly act as if "DirectoryCheckHandler ON" was specified).

Start from i 7.2, the default behavior allows directory indexes to be served even when a SetHandler directive is specified for an entire directory, but it can also result in some conflicts with modules such as mod_rewrite.

DirectoryIndex

Module: mod_dir
Syntax: DirectoryIndex disabled | local-url [local-URL ...]
Default: DirectoryIndex index.html
Context: server config, virtual host, directory, .htaccess
Override: Indexes
Origin: Apache
Example: DirectoryIndex bob.html index.html

The DirectoryIndex directive sets the list of resources to look for, when the client requests an index of the directory by specifying a / at the end of the a directory name. Local-URL is the (%-encoded) URL of a document on the server relative to the requested directory; it is usually the name of a file in the directory. Several URLs may be given, in which case the server will return the first one that it finds. If none of the resources exist and the Indexes option is set, the server will generate its own listing of the directory.

Parameter: disabled | local-url
  • The local-url parameter is the (%-encoded) URL of a document on the server relative to the requested directory; it is usually the name of a file in the directory. For example:
    DirectoryIndex index.html
  • The disabled parameter prevents mod_dir from searching for an index.

A request for http://myserver/docs/ would return http://myserver/docs/index.html if it exists, or it would list the directory if it did not exist.

The documents do not need to be relative to the directory. For example:

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

This would cause the CGI script /cgi-bin/index.pl to be run if neither index.html or index.txt existed in a directory. This same idea will also work for QSYS.LIB files. For example, if the directory index is stored in /QSYS.LIB/MYLIB.LIB/MYFILE.FILE/INDEX.MBR, you would need to specify DirectoryIndex Index.mbr.

A single argument of "disabled" prevents mod_dir from searching for an index. An argument of "disabled" will be interpreted literally if it has any arguments before or after it, even if they are "disabled" as well.

Note: Multiple DirectoryIndex directives within the same context will add to the list of resources to look for rather than replace:
Example 1:

# Set index.html as an index page, then add index.php to that list as well.

       <Directory /foo>
           DirectoryIndex index.html
           DirectoryIndex index.php
       </Directory>
Example 2:

# This is identical to example A, except it's done with a single directive.

       <Directory /foo>
          DirectoryIndex index.html index.php
       </Directory>
Example 3:

# To replace the list, you must explicitly reset it first

# In this example, only index.php will remain as an index resource.

       <Directory /foo>
           DirectoryIndex index.html
           DirectoryIndex disabled
           DirectoryIndex index.php
       </Directory>

DirectoryIndexRedirect

Module: mod_dir
Syntax: DirectoryIndexRedirect on | off | permanent | temp | seeother | 3xx-code
Default: DirectoryIndexRedirect off
Context: server config, virtual host, directory, .htaccess
Override: Indexes
Origin: Apache
Example: DirectoryIndexRedirect on

By default, the DirectoryIndex is selected and returned transparently to the client. The DirectoryIndexRedirect directive configures an external redirect for directory indexes.

Parameter: on | off | permanent | temp | seeother | 3xx-code
  • The on parameter issues a 302 redirection to the index resource:
  • The off parameter does not issue a redirection. This is the legacy behaviour of mod_dir.
  • The permanent parameter issues a 301 (permanent) redirection to the index resource.
  • The temp parameter has the same effect as on:
  • The seeother parameter issues a 303 redirection (also known as "See Other") to the index resource.
  • The 3xx-code parameter issues a redirection marked by the chosen 3xx code.

Example

DirectoryIndexRedirect on

A request for http://example.com/docs/ would return a temporary redirect to http://example.com/docs/index.html if it exists.

DirectorySlash

Module: mod_dir
Syntax: DirectorySlash on | off
Default: DirectorySlash on
Context: Server, Virtual Host, Directory, .htaccess
Override: Indexes
Origin: Apache
The DirectorySlash directive determines, whether mod_dir should fixup URLs pointing to a directory or not. Typically if a user requests a resource without a trailing slash, which points to a directory, mod_dir redirects him to the same resource, but with trailing slash for the following reasons:
  • The user is finally requesting the canonical URL of the resource
  • The directive mod_autoindex works correctly. Since mod_autoindex doesn't emit the path in the link, it would point to the wrong path.
  • The DirectoryIndex directive will be evaluated only for directories requested with trailing slash.
  • The relative URL references inside HTML pages will work correctly.
If you don't want this effect and the reasons above don't apply to you, you can turn off the redirect with the following:
# see security warning below!
<Location /some/path>
DirectorySlash Off
SetHandler some-handler
</Location>

Security Warning: Turning off the trailing slash redirect may result in an information disclosure. Consider a situation where mod_autoindex is active (Options +Indexes) and DirectoryIndex is set to a valid resource (say, index.html) and there's no other special handler defined for that URL. In this case a request with a trailing slash would show the index.html file. But a request without trailing slash would list the directory contents.

FallbackResource

Module: mod_dir
Syntax: FallbackResource disabled | local-url
Default: disabled - HTTP server will return 404 (Not Found)
Context: Server config, Virtual Host, Directory, .htaccess
Override: Indexes
Origin: Apache
Examples: FallbackResource /not-404.html

The FallbackResource directive sets a handler for any URL that doesn't map to anything in your filesystem, and would otherwise return HTTP 404 (Not Found).

    FallbackResource /not-404.php

will cause requests for non-existent files to be handled by not-404.php, while requests for files that exist are unaffected.

It is frequently desirable to have a single file or resource handle all requests to a particular directory, except those requests that correspond to an existing file or script. This is often referred to as a 'front controller.'

In earlier versions of Apache, this effect typically required mod_rewrite, and the use of the -f and -d tests for file and directory existence. This now requires only one line of configuration.

    FallbackResource /index.php

Existing files, such as images, css files, and so on, will be served normally.

Use the disabled argument to disable that feature if inheritance from a parent directory is not desired. In a sub-URI, such as http://system:port/blog/ this sub-URI has to be supplied as local-url:

Example:

     <Directory /www/webserver/htdocs/blog>
        FallbackResource /blog/index.php
     </Directory>
     <Directory /www/webserver/htdocs/blog/images>
        FallbackResource disabled
     </Directory>