How to use DAV and DirectoryIndex in Apache 2.4?

In order to fix this, disable directory indexing for the WebDAV site.

In your sites-available/site.conf file add DirectoryIndex disabled to the <Directory> declaration, like so:

    <Directory /path/to/my/webdav/dir>
                    Options Indexes FollowSymLinks MultiViews
                    AllowOverride all
                    Require all granted

                    DirectoryIndex disabled
   </Directory>

Then just reload Apache and you will no longer have that issue:

sudo service apache2 reload

For me, the following configuration solved both problems:

  • WebDAV works again
  • directory indexing, if the user uses a web browser to access the repository

It works by manually implementing the directory-indexing feature with simple rewrite rules, which are applied only for the GET request method.

The following code has to be placed inside the server config or virtual host context in the apache configuration file.

# Turn off (automatic) Directory-Indexing 
DirectoryIndex disabled

RewriteEngine On

# Rewrite rules for the root directory
RewriteCond  "%{REQUEST_METHOD}"  "(GET)"
RewriteRule  "^/$"                 "/index.php"  [L]

# Rewrite rules for other sub-directories
RewriteCond  "%{REQUEST_METHOD}"  "(GET)"
# The following line checks, if the index.php file exists
RewriteCond  "%{DOCUMENT_ROOT}/$1/index.php"  "-f"
RewriteRule  "^/(.*)/$"                 "/$1/index.php"  [L]

Don't forget to reload Apache!

Tags:

Apache

Webdav