How to use DAV and DirectoryIndex in Apache 2.4? How to use DAV and DirectoryIndex in Apache 2.4? apache apache

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 disabledRewriteEngine On# Rewrite rules for the root directoryRewriteCond  "%{REQUEST_METHOD}"  "(GET)"RewriteRule  "^/$"                 "/index.php"  [L]# Rewrite rules for other sub-directoriesRewriteCond  "%{REQUEST_METHOD}"  "(GET)"# The following line checks, if the index.php file existsRewriteCond  "%{DOCUMENT_ROOT}/$1/index.php"  "-f"RewriteRule  "^/(.*)/$"                 "/$1/index.php"  [L]

Don't forget to reload Apache!


This is the solution I am currently using, located in a .htaccess file at the root of the directory tree used by the WebDav service. In this case I do not use PHP, only html files, but it can be easily adapted:

# Turn off automatic directory indexing Options -Indexes DirectoryIndex disabled# Redirect directory requests to index.html, only for GET requestsRewriteEngine OnRewriteCond  %{REQUEST_METHOD}  "GET"RewriteCond  %{REQUEST_FILENAME}  -dRewriteRule  ^(.*)$  $1index.html  [L]

In order to launch always the requested PHP file, just replace "index.html" on the last line by the PHP file name:

RewriteRule  ^(.*)$  $1mediaManagerIndex.php  [L]