Where should nextcloud be installed under apache, and does it affect the .well-known redirect problems?

I have installed nextcloud from source (actually many years ago and moved it around since then to new servers).

In the nextcloud docs it doesn’t explicitly say to install nextcloud at /var/www/nextcloud but the example configuration and virtual hosts file indicate it is there:

<VirtualHost *:80>
  DocumentRoot /var/www/nextcloud/
  ServerName  your.server.com

  <Directory /var/www/nextcloud/>
    Require all granted
    AllowOverride All
    Options FollowSymLinks MultiViews

    <IfModule mod_dav.c>
      Dav off
    </IfModule>
  </Directory>
</VirtualHost>

This is where nextcloud is on my server.

Now the actual DocumentRoot of my server is (in 000-default.conf) /var/www/html.

In my case nextcloud is curretly accessed from a subdomain like nextcloud.mydoman.tld and nextcloud is resolved fine.

However, I am also, like many others having problems with getting error like

Your web server is not properly set up to resolve "/.well-known/carddav"

I have tried creating a .htaccess file like the following in /var/www and /var/www/html

<IfModule mod_rewrite.c>
	RewriteEngine on
	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/carddav /remote.php/dav/ [R=301,L]
	RewriteRule ^/\.well-known/caldav /remote.php/dav/ [R=301,L]
	RewriteRule ^\.well-known/nodeinfo /index.php/.well-known/nodeinfo [R=301,L]
	RewriteRule ^\.well-known/webfinger /index.php/.well-known/webfinger [R=301,L]
</IfModule>

I had it in only one of these locations at a time, and restarted apache each time before testing the configuration.

But no matter what I do I cannot get rid of these errors.

Is it possible this is because I need to move my nextcloud installation to /var/www/html/nextcloud?

If not, what do I actually have to do to get rid of these errors? Nothing I have tried helps.

For reference my Virtualhosts file for nextcloud looks like this:

<VirtualHost *:443>
	# The ServerName directive sets the request scheme, hostname and port that
	# the server uses to identify itself. This is used when creating
	# redirection URLs. In the context of virtual hosts, the ServerName
	# specifies what hostname must appear in the request's Host: header to
	# match this virtual host. For the default virtual host (this file) this
	# value is not decisive as it is used as a last resort host regardless.
	# However, you must set it for any further virtual host explicitly.
	ServerName nextcloud.<redacted>
        <IfModule mod_headers.c>
                Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains"
        </IfModule>

	ServerAdmin sysadmin@<redacted>
	DocumentRoot /var/www/nextcloud


	<Directory /var/www/nextcloud/>
		Require all granted
		AllowOverride All
		Options FollowSymLinks MultiViews

		<IfModule mod_dav.c>
			Dav off
		</IfModule>
	</Directory>

	# For most configuration files from conf-available/, which are
	# enabled or disabled at a global level, it is possible to
	# include a line for only one particular virtual host. For example the
	# following line enables the CGI configuration for this host only
	# after it has been globally disabled with "a2disconf".
	#Include conf-available/serve-cgi-bin.conf

	<IfModule mod_rewrite.c>
		RewriteEngine on
		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/carddav /remote.php/dav/ [R=301,L]
		RewriteRule ^/\.well-known/caldav /remote.php/dav/ [R=301,L]
		RewriteRule ^\.well-known/nodeinfo /index.php/.well-known/nodeinfo [R=301,L]
		RewriteRule ^\.well-known/webfinger /index.php/.well-known/webfinger [R=301,L]
	</IfModule>

	# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
	# error, crit, alert, emerg.
	# It is also possible to configure the loglevel for particular
	# modules, e.g.
	#LogLevel info ssl:warn

	ErrorLog ${APACHE_LOG_DIR}/error.log
	CustomLog ${APACHE_LOG_DIR}/access.log combined

	# For most configuration files from conf-available/, which are
	# enabled or disabled at a global level, it is possible to
	# include a line for only one particular virtual host. For example the
	# following line enables the CGI configuration for this host only
	# after it has been globally disabled with "a2disconf".
	#Include conf-available/serve-cgi-bin.conf


	SSLCertificateFile <redacted>
	SSLCertificateKeyFile <redacted>
	Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>