Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Httpd Wiki" for change 
notification.

The following page has been changed by slive:
http://wiki.apache.org/httpd/Recipes/DirectoryListings

New page:
= Directory Listing Configuration =

Here we describe various types of things that the server can send when you 
request a directory rather than an individual file.

== Trailing Slash Redirection ==

If you request a directory without including the trailing slash in its name 
(i.e. {{{http://example.com/dir}}} rather than {{{http://example.com/dir/}}}), 
then Apache must send a redirect to add the trailing slash to the URL.  This is 
necessary so relative hyperlinks will work in the resulting file.

For this to work, Apache must know the name of the server so that it can send a 
redirect back to itself.  Normally, when 
[http://httpd.apache.org/docs/trunk/mod/core.html#usecanonicalname 
UseCanonicalName] is set off, the name supplied by the client in the {{{Host}}} 
HTTP request header is used.  If {{{UseCanonicalName}}} is on, then you need to 
assure that [http://httpd.apache.org/docs/trunk/mod/core.html#servername 
ServerName] is set correctly in order for this redirect to work.

== Directory Indexes ==

When a directory is requested, Apache may be configured to send a particular 
file within that directory automatically.  This is configured with the 
[http://httpd.apache.org/docs/trunk/mod/mod_dir.html#directoryindex 
DirectoryIndex] directive.  It can list one or more files that Apache should 
search for in the directory, with the first existing file being returned to the 
client.  For example:

{{{
DirectoryIndex index.html index.htm index.php welcome.html
}}}

== Directory Listings ==

If no file from the DirectoryIndex directive can be located in the directory, 
then [http://httpd.apache.org/docs/trunk/mod/mod_autoindex.html mod_autoindex] 
can generate a listing of the directory contents.  This is turned on and off 
using the [http://httpd.apache.org/docs/trunk/mod/core.html#options Options] 
directive.  For example, to turn on directory listings for a particular 
directory, you can use

{{{
<Directory /usr/local/apache2/htdocs/listme>
  Options +Indexes
</Directory>
}}}

To prevent directory listings (for security purposes, for example), you should 
remove the {{{Indexes}}} keyword from every Options directive in your 
configuration file.  Or to prevent them only for a single directory, you can use

{{{
<Directory /usr/local/apache2/htdocs/dontlistme>
  Options -Indexes
</Directory>
}}}

=== Excluding Files ===

If you would like listings to be enabled, but you want to omit particular 
files, you can use the 
[http://httpd.apache.org/docs/trunk/mod/mod_autoindex.html#indexignore 
IndexIgnore] directive.  For example, to omit any filename starting with 
{{{tmp}}} and also the parent directory link (..), you could use

{{{
IndexIgnore tmp* ..
}}}

=== Headers and Footers ===

The directives 
[http://httpd.apache.org/docs/trunk/mod/mod_autoindex.html#headername 
HeaderName] and 
[http://httpd.apache.org/docs/trunk/mod/mod_autoindex.html#readmename 
ReadmeName] configure a file to be included, respectively, above and below the 
file listing.  If no path is given, Apache will look for these files in the 
directory being listed.  For example:

{{{
HeaderName header.html
ReadmeName footer.html
}}}

A path starting in slash can be used if you want the same files included for 
all directories:

{{{
HeaderName /site/header.html
ReadmeName /site/footer.,html
}}}

=== Styling the listing ===

The directory listing is highly configurable.  The 
[http://httpd.apache.org/docs/trunk/mod/mod_autoindex.html#indexoptions 
IndexOptions] directive gives lots of choices for different configurations and 
the [http://httpd.apache.org/docs/trunk/mod/mod_autoindex.html#indexstylesheet 
IndexStyleSheet] directive allows a CSS stylesheet to be specified.  A typical 
configuration might look like:

{{{
IndexOptions FancyIndexing HTMLTable
IndexStyleSheet /css/autoindex.css
}}}

=== Extended example ===

For a more complete example, including a configuration for the icons displayed 
with the files, see {{{conf/extra/httpd-autoindex.conf}}} as distributed with 
Apache httpd.

Reply via email to