WebDAV 405 Errors (even after trying typical troubleshooting)

Nextcloud version: 19.0.6
Operating system and version: Ubuntu 20.04.1 LTS
Apache or nginx version: Apache 2.4.41 Ubuntu
PHP version: 7.4

The issue you are facing:
While going through the Security & Setup warnings on my server, I’m running into the WebDAV warnings that my webserver is not properly resolving the ./well-known requests. Indeed, both Apache and my browser (Firefox) show the two attempts on those requests end in 405 Method not allowed errors. Despite setting up my .htaccess correctly (or so I think), it appears that Apache is not attempting to redirect the requests correctly.

I have my webserver’s document root in /var/www/html, and nextcloud resides in /var/www/nextcloud. Inside the html root folder I created an .htaccess file that looks like this:

DirectoryIndex disabled

Redirect 301 /.well-known/carddav /nextcloud/remote.php/dav
Redirect 301 /.well-known/caldav /nextcloud/remote.php/dav
 # Enable Car/CalDAV access for Nextcloud
<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteRule ^\.well-known/host-meta /nextcloud/public.php?service=host-meta [QSA,L]
  RewriteRule ^\.well-known/host-meta\.json /nextcloud/public.php?service=host-meta-json [QSA,L]
  RewriteRule ^\.well-known/webfinger /nextcloud/public.php?service=webfinger [QSA,L]
  RewriteRule ^\.well-known/carddav /nextcloud/remote.php/dav/ [R=301,L]
  RewriteRule ^\.well-known/caldav /nextcloud/remote.php/dav/ [R=301,L]

I also created the same file in my /var/www directory just in case, but no luck. Module rewrite is confirmed enabled in my server.

Is this the first time you’ve seen this error? (Y/N): Yes.

Steps to replicate it:

  1. Install Nextcloud on ubuntu using the manual package installation steps and configuration
  2. Run the server security and config. check.

The output of your Nextcloud log in Admin > Logging: (No relevant errors are logged)

The output of your config.php file in /path/to/nextcloud (make sure you remove any identifiable information!):

$CONFIG = array (
  'instanceid' => snip,
  'passwordsalt' => snip,
  'secret' => snip,
  'trusted_domains' =>
  array (
    0 => 'localhost',
    1 => my_machine,
  'datadirectory' => '/var/www/nextcloud/data',
  'dbtype' => 'mysql',
  'version' => '',
  'overwrite.cli.url' => 'https://my_machine/nextcloud/',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'dbuser' => 'nextcloud',
  'dbpassword' => snip,
  'installed' => true,
  'log_type' => 'file',
  'loglevel' => 2,
  'htaccess.RewriteBase' => '/nextcloud',
  'maintenance' => false,
  'has_rebuilt_cache' => true,
  'updater.release.channel' => 'stable',
  'updater.secret' => snip,
  'theme' => '',
  'mysql.utf8mb4' => true,

The output of your Apache/nginx/system log in /var/log/____: - - [17/Dec/2020:02:14:38 +0000] "PROPFIND /.well-known/caldav HTTP/1.1" 405 638 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:83.0) Gecko/20100101 Firefox/83.0" - - [17/Dec/2020:02:14:38 +0000] "PROPFIND /.well-known/carddav HTTP/1.1" 405 638 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:83.0) Gecko/20100101 Firefox/83.0"

Any help would be greatly appreciated!

Update: Problem solved, the errors are gone now and it’s properly redirecting.

The solution? For some reason, no amount of .htaccess’ing would work. I had to add two lines to the site-config, in /etc/apache2/sites-available/nextcloud.conf:

# Fix WebDAV redirect issues
Redirect 301 /.well-known/carddav /nextcloud/remote.php/dav
Redirect 301 /.well-known/caldav /nextcloud/remote.php/dav

Note that those lines go outside of the tags, in the root of the file. After a quick sudo systemctl restart apache2, everything appears to be fine.