From ae3b972a22d7c1722dfde1349e8c4fa710df1baa Mon Sep 17 00:00:00 2001 From: Greg Gauthier Date: Sat, 3 Apr 2021 11:45:19 +0100 Subject: [PATCH] document caldav problem in nextcloud --- content/post/nextcloud-caldav-error.md | 48 ++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 content/post/nextcloud-caldav-error.md diff --git a/content/post/nextcloud-caldav-error.md b/content/post/nextcloud-caldav-error.md new file mode 100644 index 0000000..cb78e98 --- /dev/null +++ b/content/post/nextcloud-caldav-error.md @@ -0,0 +1,48 @@ +--- +title: "Nextcloud Caldav Discovery Problem" +date: 2021-04-03T11:27:28+01:00 +draft: true +--- + +Recently, I setup a self-hosted nextcloud instance, for my own personal use. One of the primary uses I had for this service, besides storing sharable content on the internet, was to have a central place where I stored and synced things like appointments, meetings, and tasks. That requires a working CALDAV and CARDDAV discovery service, and nextcloud has this feature, so I was eager to get it up and running. + +Unfortunately, out of the box, it wasn't working. I tried all sorts of suggestions which I culled from the internet, which involved modifying my apache config, adding explicit Redirect statements to htaccess files, and even moving files around. Nothing worked. Not even the documentation from nextcloud itself was any help. + +Then, after a day of staring blankly at the problem, I suddenly realized what was wrong. There was a simple `regex` typo in the htaccess configuration that came from nextcloud. Let's see if you can see the difference. Here's what nextcloud gives you: + +```  + + RewriteEngine on + RewriteCond %{HTTP_USER_AGENT} DavClnt + RewriteRule ^$ /remote.php/webdav/ [L,R=302] + RewriteRule .* - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization}] + RewriteRule ^\.well-known/carddav /remote.php/dav/ [R=301,L] + RewriteRule ^\.well-known/caldav /remote.php/dav/ [R=301,L] + RewriteRule ^remote/(.*) remote.php [QSA,L] + RewriteRule ^(?:build|tests|config|lib|3rdparty|templates)/.* - [R=404,L] + RewriteRule ^\.well-known/(?!acme-challenge|pki-validation) /index.php [QSA,L] + RewriteRule ^(?:\.(?!well-known)|autotest|occ|issue|indie|db_|console).* - [R=404,L] + +``` + +and here is what I ended up running successfully with: + +``` + + RewriteEngine on + RewriteCond %{HTTP_USER_AGENT} DavClnt + RewriteRule ^$ /remote.php/webdav/ [L,R=302] + RewriteRule .* - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization}] + RewriteRule ^/\.well-known/carddav /remote.php/dav/ [R=301,L] + RewriteRule ^/\.well-known/caldav /remote.php/dav/ [R=301,L] + RewriteRule ^remote/(.*) remote.php [QSA,L] + RewriteRule ^(?:build|tests|config|lib|3rdparty|templates)/.* - [R=404,L] + RewriteRule ^\.well-known/(?!acme-challenge|pki-validation) /index.php [QSA,L] + RewriteRule ^(?:\.(?!well-known)|autotest|occ|issue|indie|db_|console).* - [R=404,L] + +``` + +Can you see it? Hint: RewriteRules require leading forward-slashes to work. But REGEX rules require leading back-slashes to escape special characters in uris. So, I had to change this `^\.` to this `^/\.` and everything started working. + +Hopefully, for those of you into self-hosting, this will save you the hours of pain and suffering it cost me. +