Properly resolving "/.well-known/caldav" or "/.well-known/carddav"

I’m going over issues in my Nextcloud (18.0.4 – just updated) & this is one of the few issues left!

* Your web server is not properly set up to resolve "/.well-known/caldav". Further information can be found in the [documentation](https://docs.nextcloud.com/server/18/go.php?to=admin-setup-well-known-URL).
* Your web server is not properly set up to resolve "/.well-known/carddav". Further information can be found in the [documentation](https://docs.nextcloud.com/server/18/go.php?to=admin-setup-well-known-URL).

I’m using manual install on Ubuntu Server 18.04 (headless) with Apache2 & the NC home path is “/var/www/nextcloud”

the mod_rewrite section of my .htaccess file in

<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{HTTP_USER_AGENT} DavClnt
  RewriteRule ^$ /remote.php/webdav/ [L,R=302]
  RewriteRule .* - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
  RewriteRule ^\.well-known/host-meta /public.php?service=host-meta [QSA,L]
  RewriteRule ^\.well-known/host-meta\.json /public.php?service=host-meta-json [QSA,L]
  RewriteRule ^\.well-known/webfinger /public.php?service=webfinger [QSA,L]
  RewriteRule ^\.well-known/nodeinfo /public.php?service=nodeinfo [QSA,L]
  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]
  RewriteCond %{REQUEST_URI} !^/\.well-known/(acme-challenge|pki-validation)/.*
  RewriteRule ^(?:\.|autotest|occ|issue|indie|db_|console).* - [R=404,L]
</IfModule>

I don’t know if this is related or not but I am currently accessing my path via https://nextcloud.mydomain.com/nextcloud rather than just https://nextcloud.mydomain.com as https://nextcloud.mydomain.com goes to the default Apache success page.

Thanks in advance!!

PS: There are a number of similar topics, but no relevant answers in those posts that I found :frowning:

Hi.
I’ve got the same issue, did you ever resolve this problem?
When I look in the documents, if you have your nextcloud in a subfolder, you should add this behind the well-known lines.

e.g ^.well-known/carddav /nextcloud/remote.php/dav/ [R=301,L]

I did that, still didn’t work. So if you did get a solution, I would be very happy if you shared it.

Kent,

I never did get it working. Honestly it’s been a while since I’ve looked at this…but if you ever find a solution, feel free to post it! I’d much appreciate it :slight_smile:

1 Like

This is my Solution that worked for my.
If your working with Apache this should help place it in your vhost config.

        RewriteEngine On
            RewriteRule ^/\.well-known/carddav https://%{SERVER_NAME}/remote.php/dav/ [R=301,L]
            RewriteRule ^/\.well-known/caldav https://%{SERVER_NAME}/remote.php/dav/ [R=301,L]

if you doesnt use https use this

        RewriteEngine On
            RewriteRule ^/\.well-known/carddav http://%{SERVER_NAME}/remote.php/dav/ [R=301,L]
            RewriteRule ^/\.well-known/caldav http://%{SERVER_NAME}/remote.php/dav/ [R=301,L]
2 Likes

@Adriaan_van_Vliet It looks like the difference between your entry and my entry is the “/” in the characters: ^/\. I’ll give that a try! Glad to have something concrete to try! With any luck, it’ll even work :slight_smile:

an did it work ?

@Adriaan_van_Vliet sorry to leave you hanging. But I am trying to upgrade to NC 21 right now, and haven’t had a chance to try this. Currently stuck on a php error where I should see NC…

Just wanted to report back for the sake of closure. Upgrading ended up being a total nightmare (new php → new host OS → not a simple upgrade). So I ended up creating a new host for Nextcloud & just pointing to the same config files & database & data & all that. Apparently this issue fixed itself.

By that I actually mean two related but distinct things. When I first installed Nextcloud 21, I had a list of issues in the management tab, including 4 (not just the 2 I was used to) related to well-known. I ran a few of the fixes, but did nothing to address these specifically before going to bed. When I checked on it the next morning, all the “well-known” issues were fixed.

So I guess it’s solved? Not sure how (unless they made a change to the config file)–but I’m not looking a gift horse in the mouth!

Regardless, I appreciate the help & didn’t want to leave you hanging!

Update for NC 21 (relevant for previous versions as well):

I had the same issue, but in my experience it’s always an issue of having the proper rewrite rules set in your server configuration. Adrian’s solution should work for any version; for SSL:

         RewriteRule ^/\.well-known/carddav https://%{SERVER_NAME}/remote.php/dav/ [R=301,L]
        RewriteRule ^/\.well-known/caldav https://%{SERVER_NAME}/remote.php/dav/ [R=301,L]

I have not been able to get webfinger or nodeinfo to work, however.

There is some nice documentation on this in the official Nextcloud troubleshooting: https://docs.nextcloud.com/server/21/admin_manual/issues/general_troubleshooting.html#service-discovery

Unfortunately, I was not able to get this to work. I tried updating the .htaccess in all three places, but no luck.

  • ./var/www/nextcloud/.htaccess
  • ./var/www/nextcloud/config/.htaccess
  • ./var/www/nextcloud/data/.htaccess

Any guidance on this?

Well, for what it’s worth, here is my “solution” to get all of the rewrites to work.
Basically it’s @Adriaan_van_Vliet 's solution of calling the server-URL during rewrites.
I’m currently running NC 25.0.3 on Debian 11.
Installation directory of NC is “/var/www/nextcloud”
The changes I made were made to the file “/var/www/nextcloud/.htaccess”
These changes were to edit the file to include the following rewrites:
"
RewriteRule ^\.well-known/carddav http(s)://%{SERVER_NAME}/remote.php/dav/ [R=301,L]
RewriteRule ^\.well-known/caldav http(s)://%{SERVER_NAME}/remote.php/dav/ [R=301,L]
RewriteRule ^\.well-known/webfinger http(s)://%{SERVER_NAME}/index.php/.well-known/webfinger [R=301,L]
RewriteRule ^\.well-known/nodeinfo http(s)://%{SERVER_NAME}/index.php/.well-known/nodeinfo [R=301,L]
"
Please make sure to adapt the “http(s)://%{SERVER_NAME}”-part to match your own situation.

I hope this helps someone and thanks to @Adriaan_van_Vliet again for originally posting this solution in the first place.

Adding @LordMort’s & @Adriaan_van_Vliet’s ‘solution’ to our Apache vhost fixed this “web server is not properly set up” warning in our Nextcloud Hub 4 (26.0.1) setup on Debian 11.6. :+1:

For HAProxy users, a shorter rewrite that also fixes these warnings;

 acl dav path_beg -i { /.well-known/carddav || /.well-known/caldav }
 http-request set-path /remote.php/dav if dav

After a long time looking for the right recipe to get this working I finally found the solution.

You may want to refer to the various documentation versions which were changed over time (13-19 or 20 vs. 21):

In fact I struggled a long time with the right syntax for some trailing or leading slash being wrong on my Linux based host.

.htaccess:

php_value open_basedir none

<IfModule mod_rewrite.c>
RewriteEngine on
  #RewriteLog "/var/log/apache2/rewrite.log"
  #RewriteLogLevel 3

  # If your Nextcloud instance is installed in a subfolder called nextcloud 
  # and you're running Apache create or edit the .htaccess file within the document root
  # of your Web server and add the following lines:
  # https://docs.nextcloud.com/server/latest/admin_manual/issues/general_troubleshooting.html#service-discovery

  RewriteRule ^\.well-known/carddav https://%{SERVER_NAME}/nextcloud/remote.php/dav [R=301,L]
  RewriteRule ^\.well-known/caldav https://%{SERVER_NAME}/nextcloud/remote.php/dav [R=301,L]
  RewriteRule ^\.well-known/webfinger https://%{SERVER_NAME}/nextcloud/index.php/.well-known/webfinger [R=301,L]
  RewriteRule ^\.well-known/nodeinfo https://%{SERVER_NAME}/nextcloud/index.php/.well-known/nodeinfo [R=301,L]
</IfModule>

Obviously the https://%{SERVER_NAME} prefix is/was not strictly necessary in my case, though it would redirect clients to the secure https:// protocol for sure, which is a good thing [TM].
But the trailing slash after /nextcloud/remote.php/dav/ was superfluous in my case and it worked only after I removed that from the examples given here, there and elsewhere before.

Actually many of these .well-known URIs are defined in RFCs which you can find a list here:
https://www.iana.org/assignments/well-known-uris/well-known-uris.xhtml

Just to add some information to this thread. I solved the problem by adding the following to the nextcloud-le-ssl.conf file in /etc/apache2/sites-available.

RewriteEngine on
RewriteRule ^/.well-known/carddav /remote.php/dav [R=301,L]
RewriteRule ^/.well-known/caldav /remote.php/dav [R=301,L]
RewriteRule ^/.well-known/webfinger /index.php/.well-known/webfinger [R=301,L]
RewriteRule ^/.well-known/nodeinfo /index.php/.well-known/nodeinfo [R=301,L]

People who actually know what they’re doing may want to criticise this as I’m just starting and floundering around, but it worked and got rid of the error message in my profile Administration overview. I hope this helps someone

It’s been a long time and this is not strictly related to caldav and carddav, but for those who still struggle with the issue regarding the redirection of /.well-known services and find this thread through a web search, they might find some additional information on why the tests for webfinger and nodeinfo might fail despite correct redirection in my comment here.
(Apologies for the noise.)

1 Like

I am also having similar problems. Maybe someone can help.

I am using yunohost to self-host 2 different Nextcloud instances on the same server. Let’s call the domain for the first instance www.domainA.com and the second www.domainB.com.

The first instance, www.domainA.com functions perfectly and I am able to connect to CalDAV via the url https://www.domainA.com/remote.php/dav/principals/users/username/

I am not able to connect to the CalDav on the second instance.

On my server, the file path to the first instance of nextcloud is /var/www/nextcloud/ and the file path to the second instance of Nextcloud is /var/www/nextcloud__2/

For what it is worth, if I use a web browser and go www.domainB.com/.well-known/caldav
I am redirected to the webdav interface and after entering my user credentials I see “This is the WebDAV interface, so I know the self-service discovery.

Does anyone know the modifications I need ?

Thank you.

On my system Ubuntu-22.04 the module reference was incorrect (this ghosted me for an entire day).

The NextCloud documents example has:
<IfModule mod_rewrite.c> ... </IfModule>

On my system the modules are named:
<IfModule rewrite_module> ... </IfModule>

of course, make sure you have the rewrite_module enabled
$> a2enmod rewrite

finally restart apache2
$> systemctl restart apache2

Simple mistake, but if it happened to me – thought I’d share in hopes of saving someone else their day.

For that matter, every module reference in the NextCloud .htaccess file was incorrectly named. Thus, none of the lines were engaging.